This is because await fetchEventSource does not resolve until onclose/onerror fires. I then realised that the readyState value isn't actually read anywhere, and isn't exposed to the front-end either, so made sense to raise a PR to clean it up.
Looks good to me.
In the future we should probably expose it properly, maybe even as a readable, it could be useful for debugging purposes.
I'll merge this and release a patch.
Removed
StreamState
type andreadyState
property fromstream.js
as it was unused.I first noticed that
readyState = OPEN
was not reached unless there is a reconnect.https://github.com/tncrazvan/sveltekit-sse/blob/eb99d00f2611ca00dd034df5530cdc906bad48f8/src/lib/stream.js#L189
This is because
await fetchEventSource
does not resolve untilonclose
/onerror
fires. I then realised that thereadyState
value isn't actually read anywhere, and isn't exposed to the front-end either, so made sense to raise a PR to clean it up.