Repository navigation
Releases: EventSource/eventsource
Release list
v5.1.2
Patch Changes
-
#363
c4d6b9aThanks @brennanbutler01! - Abort the underlying request when a response fails EventSource validation. -
#362
627eb17Thanks @brennanbutler01! - Stop dispatching buffered messages when an event listener closes the connection.
v5.1.1
Patch Changes
-
#358
de3c0aeThanks @pacocartones! - FixedMessageEvent.lastEventIdbeing empty when a message omits the id fieldThe
lastEventIdattribute is the last event ID string of the event source, so an explicitidfield persists until another one replaces it. Message events were dispatched with the current event's ownidinstead of that buffer, which leftlastEventIdempty on every event that omittedid, even though the buffer still held the earlier value and would have been sent asLast-Event-IDon reconnect. -
17a9772Thanks @rexxars! - Fixed ID-only event blocks not updatingMessageEvent.lastEventIdorLast-Event-IDon reconnect.
v5.1.0
Minor Changes
-
#355
d8370e4Thanks @rexxars! - Typed response body chunks as buffers instead ofunknownReaderLiketyped chunks read off the response body asunknown, but they are handed to aTextDecoder, which only accepts buffers and throws on anything else. So a reader yielding anything else was never usable, and the type said otherwise. It also hid a type error in the client itself, which only surfaces when compiling against TypeScript'sdomlibrary: the node typings resolve the chunk toany, while thedomlibrary resolves it to{}.Chunks are now typed as
Uint8Array | DataView | ArrayBuffer, which is what both the node and DOM typings accept, and which everyfetch()implementation yields. Nothing changes at runtime.If you pass a custom
fetch()that returns a hand-rolled body, and your reader's chunk type is wider than the above, egunknownorany, it will no longer be assignable. Returning a realResponse, or a reader that yieldsUint8Arraychunks, is unaffected. -
#355
008f07eThanks @rexxars! - Declared thethistype for theonerror,onmessageandonopenpropertiesaddEventListener()already declared that listeners are called with the EventSource instance asthis, but theon*properties did not, sothiswas an implicitanyin handlers assigned to them (an error undernoImplicitThis). They now matchaddEventListener()and the nativeEventSource:eventSource.onmessage = function (event) { console.log(this.url, event.data) // `this` is now typed }
Handlers that declare an incompatible
this, eg an unbound class method typed withthis: MyClass, will now be rejected where they were previously accepted. Arrow functions and handlers that ignorethisare unaffected. -
#355
3512addThanks @rexxars! - Made the exportedEventSourcetype structural, so other implementations can satisfy itEventSourcewas exported as a class holding hard-private (#) fields, which makes TypeScript emit a#privatebrand into the declaration file and turns the exported type nominal. A consumer writingfunction connect(es: EventSource)against this package could not pass the nativeEventSource, a mock, or any other implementation, even when the shape matched exactly.The implementation class is now internal, and
EventSourceis exported as aninterfaceplus a const holding the constructor. As a result:- The native
EventSource, along with mocks and stubs, is assignable to the exportedEventSourcetype - The exported value and
globalThis.EventSourceare interchangeable in both directions, which helps libraries that accept an EventSource implementation to construct - A new
EventSourceConstructortype is exported for that case
Nothing changes at runtime:
new EventSource(...),instanceof, subclassing, the readyState statics,EventSource.name, inspected output and theeventsource.supports-fetch-overridesymbol all behave as before, and the internal state is still held in real#privatefields. - The native
Patch Changes
-
#357
8e5c691Thanks @rexxars! - FixedoriginandlastEventIdbeing empty on Cloudflare Workersworkerd accepts
datafrom theMessageEventconstructor's init dictionary but silently dropsoriginandlastEventId, so message events dispatched on Cloudflare Workers arrived withoriginset tonullandlastEventIdto an empty string. Both are now assigned explicitly when the constructor did not take them, which leaves every other runtime untouched.
v5.0.0
Major Changes
- #349
b195e70Thanks @rexxars! - - BREAKING CHANGE: The client now fails the connection, emitting an error without reconnecting, if the parser buffers 100 MB without receiving a valid, complete EventSource line. Configure a different limit withmaxBufferSize; ideally, servers should emit smaller chunks or newlines more frequently.- BREAKING CHANGE: Node.js 22.12 or later is now required. Older Node.js versions may still work, but are not supported or guaranteed going forward because Node.js 20 is out of LTS.
- BREAKING CHANGE: The separate CommonJS variant is no longer published. Node.js 22.12 and later transparently supports
require()of ESM, so most CommonJS consumers should continue to work. This removes the dual-package hazard. - BREAKING CHANGE: Chrome versions before 84, Safari before 15, Firefox before 105, Edge before 84, and JavaScript environments without private fields, methods, and accessors are no longer supported.
- BREAKING CHANGE: When both an
on*property handler and anaddEventListener()listener are registered for the same event, they now run in registration order instead of always running theon*handler first. Code that relied on the old order can observe a different callback sequence. - Unref reconnection timers where the runtime supports it, so pending reconnects do not keep the process alive.
v4.1.1
Patch Changes
- #351
6127f40Thanks @rexxars! - Allow avalueof any type inReaderLikedone-results. TypeScript 5.9's DOM lib typesReadableStreamDefaultReader.read()'s done-result as{done: true, value: T | undefined}, so a customfetchreturning aResponse-shaped body no longer satisfiedFetchLikeResponseon TypeScript 5.9 and newer, forcing consumers to hand-wrap the reader.
v4.1.0
v4.0.0
4.0.0 (2025-05-13)
⚠ BREAKING CHANGES
FetchLikeInitis now removed. Use
EventSourceFetchInit.- Drop support for Node.js v18, as it is end-of-life.
Features
- require node.js v20 or higher (91a3a48)
Bug Fixes
- drop
FetchLikeInittype. UseEventSourceFetchInitinstead. (6786e46)
This release is also available on: