npm / eventsource
eventsource
What changed in eventsource 2 to 5, from its official release notes, upgrade guides and advisories. Sources checked 2026-11-30.
23 breaking2 new APIs and options1 performance3 behavior and defaults10 fixes and other
See which of these apply to your code, ranked, in your agent:
npx @unstale/cli initeventsource 522 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 10
URL objects are copied during construction, so later caller mutations do not change the exposed URL or reconnection target.
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 44 changes
Breaking changes 2
FetchLikeInit was removed; use EventSourceFetchInit instead.
Node.js v20 or higher is required; support for Node.js v18 was dropped.
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.
eventsource 311 changes
Breaking changes 11
Empty options no longer disable certificate checks.
dispatchEvent now emits the entire event object.
A custom fetch function can replace dropped headers, proxy, and https.* options.
The headers option in the init dict is dropped; pass a custom fetch function instead.
Built-in HTTP/HTTPS proxy support is dropped; pass a custom fetch function instead.
The https.* options are dropped; provide an agent or dispatcher through a custom fetch function instead.
The module uses a named export instead of a default export.
Node.js versions below v18 are no longer supported.
The default reconnect delay is 3 seconds instead of 1 second.
Reconnecting after a redirect always uses the original URL, including when the status code is HTTP 307.
The UMD bundle is no longer provided; use a bundler.
eventsource 22 changes
Breaking changes 1
Node >= 12 is now required to run the package.
Performance 1
Buffer size is preallocated when reading data, increasing performance with large messages.