-
#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.
-
#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
-
#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.
- #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.
- #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.
4.1.0 (2025-11-19)
- declare fetch override support symbol on class (5575122)
4.0.0 (2025-05-13)
FetchLikeInitis now removed. UseEventSourceFetchInit.- Drop support for Node.js v18, as it is end-of-life.
- require node.js v20 or higher (91a3a48)
- drop
FetchLikeInittype. UseEventSourceFetchInitinstead. (6786e46)
3.0.7 (2025-05-09)
- mark fetch init properties required in typings (1282872)
3.0.6 (2025-03-27)
- upgrade parser to latest version, improving performance (59a5ddd)
3.0.5 (2025-01-28)
- include
messageandcodeon errors when logging in node.js and deno (f2596b3)
3.0.4 (2025-01-28)
- ensure
messageis set on ErrorEvent on network errors (d1dc711)
3.0.3 (2025-01-27)
- bundle event listener typings (2c51349)
3.0.2 (2024-12-13)
- reference possibly missing event typings (d3b6849)
3.0.1 (2024-12-07)
- run build prior to publishing (f86df19)
3.0.0 (2024-12-07)
- Drop support for Node.js versions below v18
- The module now uses a named export instead of a default export.
- UMD bundle dropped. Use a bundler.
headersin init dict dropped, pass a customfetchfunction instead.- HTTP/HTTPS proxy support dropped. Pass a custom
fetchfunction instead. https.*options dropped. Pass a customfetchfunction that provides an agent/dispatcher instead.- New default reconnect delay: 3 seconds instead of 1 second.
- Reconnecting after a redirect will now always use the original URL, even if the status code was HTTP 307.
dispatchEventnow emits entire event object (eb430c0)- empty options no longer disable certificate checks (372d387)
2.0.2 (2022-05-12)
- strip sensitive headers on redirect to different origin (10ee0c4)
2.0.1 (2022-04-25)
- Fix
URL is not a constructorerror for browser (#268 Ajinkya Rajput)
2.0.0 (2022-03-02)
- Node >= 12 now required (#152 @HonkingGoose)
- Preallocate buffer size when reading data for increased performance with large messages (#239 Pau Freixes)
- Removed dependency on url-parser. Fixes CVE-2022-0512 & CVE-2022-0691 (#249 Alex Hladin)
- NPM download badge links to malware (8954d63)
1.1.2 (2022-06-08)
- Inline origin resolution, drops
originaldependency (#281 Espen Hovlandsdal)
1.1.1 (2022-05-11)
- Do not include authorization and cookie headers on redirect to different origin (#273 Espen Hovlandsdal)
1.1.0 (2021-03-18)
- Improve performance for large messages across many chunks (#130 Trent Willis)
- Add
createConnectionoption for http or https requests (#120 Vasily Lavrov) - Support HTTP 302 redirects (#116 Ryan Bonte)
- Prevent sequential errors from attempting multiple reconnections (#125 David Patty)
- Add
newto correct test (#111 Stéphane Alnet) - Fix reconnections attempts now happen more than once (#136 Icy Fish)
1.0.7 (2018-08-27)
- Add dispatchEvent to EventSource (#101 Ali Afroozeh)
- Added
checkServerIdentityoption (#104 cintolas) - Surface request error message (#107 RasPhilCo)
1.0.6 (2018-08-23)
- Fix issue where a unicode sequence split in two chunks would lead to invalid messages (#108 Espen Hovlandsdal)
1.0.5 (2017-07-18)
- Check for
windowexisting before polyfilling. (#80 Neftaly Hernandez)
1.0.4 (2017-06-19)
- Pass withCredentials on to the XHR. (#79 Ken Mayer)
1.0.2 (2017-05-28)
- Fix proxy not working when proxy and target URL uses different protocols. (#76 Espen Hovlandsdal)
- Make
close()a prototype method instead of an instance method. (#77 Espen Hovlandsdal)
1.0.1 (2017-05-10)
- Reconnect if server responds with HTTP 500, 502, 503 or 504. (#74 Vykintas Narmontas)
1.0.0 (2017-04-17)
- Add missing
removeEventListener-method. (#51 Yucheng Tu / Espen Hovlandsdal) - Add ability to customize https options. (#53 Rafael Alfaro)
- Add readyState constants to EventSource instances. (#66 Espen Hovlandsdal)
- Fix EventSource reconnecting on non-200 responses. (af84476 Espen Hovlandsdal)
0.2.3 (2017-04-17)
- Fix
onConnectionClosedfiring multiple times resulting in multiple connections. (#61 Phil Strong / Duncan Wong)
- Revert "Protects against multiple connects" (3887a4a)
0.2.2 (2017-02-28)
- Don't include test files in npm package. (#56 eanplatter)
0.2.1 (2016-02-28)
- Add http/https proxy function. (#46 Eric Lu)
- Drop support for Node 0.10.x and older (Aslak Hellesøy).
- Fix
close()for polyfill. (#52 brian-medendorp) - Fix reconnect for polyfill. Only disable reconnect when server status is 204. (Aslak Hellesøy).
0.2.0 (2016-02-11)
- Renamed repository to
eventsource(since it's not just Node, but also browser polyfill). (Aslak Hellesøy). - Compatibility with webpack/browserify. (#44 Adriano Raiano).
0.1.6 (2015-02-09)
0.1.5 (2015-02-08)
- Refactor tests to support Node.js 0.12.0 and Io.js 1.1.0. (Aslak Hellesøy)
0.1.4 (2014-10-31)
- Expose
statusproperty onerrorevents. (#40 Adriano Raiano)
0.1.3 (2014-09-17)
- Made message properties enumerable. (#37 Golo Roden)
0.1.2 (2014-08-07)
0.1.1 (2014-05-18)
- Fix message type. (#33 Romain Gauthier)
0.1.0 (2014-03-07)
0.0.10 (2013-11-21)
- Provide
Eventargument onopenanderrorevent (#30, #31 Donghwan Kim) - Expose
lastEventIdon messages. (#28 mbieser)
0.0.9 (2013-10-24)
- Old "last-event-id" used on reconnect (#27 Aslak Hellesøy)
0.0.8 (2013-09-12)
- Allow unauthorized HTTPS connections by setting
rejectUnauthorizedto false. (Aslak Hellesøy)
- EventSource still reconnected when closed (#24 FrozenCow)
0.0.7 (2013-04-19)
- Explicitly raise an error when server returns http 403 and don't continue (#20 Scott Moak)
- Added ability to send custom http headers to server (#21, #9 Scott Moak)
- Switched from testing with Nodeunit to Mocha (Aslak Hellesøy)
- Fix Unicode support to cope with Javascript Unicode size limitations (#23, #22 Devon Adkisson)
- Graceful handling of parse errors (#19 Aslak Hellesøy)
0.0.6 (2013-01-24)
- Add Accept: text/event-stream header (#17 William Wicks)
0.0.5 (2012-02-12)
- Add no-cache and https support (#10 Einar Otto Stangvik)
- Ensure that Last-Event-ID is sent to the server for reconnects, as defined in the spec (#8 Einar Otto Stangvik)
- Verify that CR and CRLF are accepted alongside LF (#7 Einar Otto Stangvik)
- Emit 'open' event (#4 Einar Otto Stangvik)
0.0.4 (2012-02-10)
- Automatic reconnect every second if the server is down. Reconnect interval can be set with
reconnectInterval(not in W3C spec). (Aslak Hellesøy)
0.0.3 (2012-02-10)
- Jison based eventstream parser (#2 Einar Otto Stangvik)
0.0.2 (2012-02-08)
- Use native EventListener (Aslak Hellesøy)
- First release (Aslak Hellesøy)