eventsource icon indicating copy to clipboard operation
eventsource copied to clipboard

Use native EventSource in browsers

Open Frando opened this issue 1 year ago • 2 comments

Hi, this PR adds a browser field to package.json, with a browser.js that re-exports window.EventSource in CommonJS format. This makes the package easily compatible with CommonJS based bundlers (e.g. vite).

Frando avatar Jul 06 '22 15:07 Frando

👎🏻 use standard exports field instead.

piranna avatar Jul 06 '22 21:07 piranna

I don't think this is a decision to be taken lightly.

Personally, I feel that this module is not a great fit for the browser even when using polyfills for http, https, url and similar, since it adds a significant amount of code and complexity. Having said that, this PR would be a big breaking change, and will only work in browsers with a native EventSource implementation. While that is thankfully the case for most modern browsers, it is not a drop-in replacement. For instance, the second argument to the constructor does not provide any way to specify headers in the browser, so it creates a mismatch in behavior between node and the browser which is annoying to deal with.

rexxars avatar Jul 07 '22 05:07 rexxars