npm / eventsource
eventsource
What changed in eventsource 4 to 5, from its official release notes, upgrade guides and advisories. Sources checked 2026-10-18.
9 breaking2 new APIs and options3 behavior and defaults9 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initeventsource 521 changes
Breaking changes 9
Handlers assigned to onerror now have the EventSource instance as their declared this type; handlers with an incompatible this are rejected.
Handlers assigned to onmessage now have the EventSource instance as their declared this type; handlers with an incompatible this are rejected.
Handlers assigned to onopen now have the EventSource instance as their declared this type; handlers with an incompatible this are rejected.
Response body reader chunks are now typed as Uint8Array | DataView | ArrayBuffer instead of unknown, so custom fetch implementations with wider chunk types may no longer be assignable.
Support is dropped for Chrome before 84, Safari before 15, Firefox before 105, Edge before 84, and JavaScript environments without private fields, methods, and accessors.
The separate CommonJS variant is no longer published; Node.js 22.12 and later transparently supports require() of ESM.
When an on* property handler and an addEventListener() listener are registered for the same event, they run in registration order instead of always running the on* handler first.
The parser now fails the connection and emits an error without reconnecting after buffering 100 MB without a valid, complete EventSource line; configure a different limit with maxBufferSize.
Node.js 22.12 or later is now required; older versions are no longer supported or guaranteed.
New APIs and options 1
A new exported type describes the EventSource constructor for libraries that accept an implementation to construct.
Behavior and default changes 2
The exported EventSource type is now structural, allowing the native EventSource, mocks, and stubs with a matching shape to be assigned to it.
Reconnection timers are unrefed where the runtime supports it, so pending reconnects do not keep the process alive.
Fixes and other changes 9
Avoids double-encoding non-ASCII event IDs during reconnects that use Cloudflare Workers' native fetch.
Sends event IDs as UTF-8 bytes on reconnect, preventing fetch errors and ensuring IDs with non-ASCII characters are encoded as specified.
Accepts case variations of the MIME type and rejects different subtypes such as text/event-streaming.
Buffered messages stop dispatching when an event listener closes the connection.
The underlying request is aborted when a response fails EventSource validation.
ID-only event blocks now update the event ID used for
Last-Event-IDon reconnect.Message events now use the buffered last event ID when an event omits an id field, preserving the previous ID.
Message events dispatched on Cloudflare Workers now have lastEventId explicitly assigned when the constructor does not retain it.
Message events dispatched on Cloudflare Workers now have origin explicitly assigned when the constructor does not retain it.
eventsource 42 changes
New APIs and options 1
A fetch override support symbol is declared on the class, enabling typed fetch overrides.
Behavior and default changes 1
Done-results now allow a value of any type, so custom fetch implementations returning Response-shaped bodies satisfy FetchLikeResponse with TypeScript 5.9 and newer.