unstale

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 init

@unstale/cli on npm

eventsource 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.

    5.1.0release notes

  • Handlers assigned to onmessage now have the EventSource instance as their declared this type; handlers with an incompatible this are rejected.

    5.1.0release notes

  • Handlers assigned to onopen now have the EventSource instance as their declared this type; handlers with an incompatible this are rejected.

    5.1.0release notes

  • 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.

    5.1.0release notes

  • 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.

    5.0.0release notes

  • The separate CommonJS variant is no longer published; Node.js 22.12 and later transparently supports require() of ESM.

    5.0.0release notes

  • 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.

    5.0.0release notes

  • 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.

    5.0.0release notes

  • Node.js 22.12 or later is now required; older versions are no longer supported or guaranteed.

    5.0.0release notes

New APIs and options 1

  • A new exported type describes the EventSource constructor for libraries that accept an implementation to construct.

    5.1.0release notes

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.

    5.1.0release notes

  • Reconnection timers are unrefed where the runtime supports it, so pending reconnects do not keep the process alive.

    5.0.0release notes

Fixes and other changes 9

  • Avoids double-encoding non-ASCII event IDs during reconnects that use Cloudflare Workers' native fetch.

    5.1.3release notes

  • Sends event IDs as UTF-8 bytes on reconnect, preventing fetch errors and ensuring IDs with non-ASCII characters are encoded as specified.

    5.1.3release notes

  • Accepts case variations of the MIME type and rejects different subtypes such as text/event-streaming.

    5.1.3release notes

  • Buffered messages stop dispatching when an event listener closes the connection.

    5.1.2release notes

  • The underlying request is aborted when a response fails EventSource validation.

    5.1.2release notes

  • ID-only event blocks now update the event ID used for Last-Event-ID on reconnect.

    5.1.1release notes

  • Message events now use the buffered last event ID when an event omits an id field, preserving the previous ID.

    5.1.1release notes

  • Message events dispatched on Cloudflare Workers now have lastEventId explicitly assigned when the constructor does not retain it.

    5.1.0release notes

  • Message events dispatched on Cloudflare Workers now have origin explicitly assigned when the constructor does not retain it.

    5.1.0release notes

eventsource 42 changes

New APIs and options 1

  • A fetch override support symbol is declared on the class, enabling typed fetch overrides.

    4.1.0release notes

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.

    4.1.1release notes