fetch-event-source
fetch-event-source copied to clipboard
Page Visibility based connection retry is not happening in Error scenario
As per the current implementation, whenever the page visibility changes the connection will be disconnected & then reconnect only after the page comes back to visibility (during the time of page hidden, no server call is triggered). But in case of error scenario, even when page is hidden, we are triggering the reconnect request to server.
Sample code to replicate the issue:
fetchEventSource('https://sample.api-service.com/stream', {
openWhenHidden: false,
onopen (res) { throw new Error("Dummy Error"); },
onerror (err) { return 1000; },
}
with the above code executed, the connection keeps failing and tries to reconnect for every 1 second. So far, fine. But when we navigate away from the page (document visibility goes to hidden), even then the server calls are getting triggered in the background.
Need to handle this and make sure that the reconnect calls are not triggers even when page visibility is off.
@RoXuS @vishwam Can someone please tell if I can work on this issue myself ?
You can try setting it to true.
fetchEventSource('https://sample.api-service.com/stream', {
openWhenHidden: true,
onopen (res) { throw new Error("Dummy Error"); },
onerror (err) { return 1000; },
}
on ios safari it seems this still doesn't work if the safari is in the background when the message is received, is there a fix for this
is there a way to keep fetching in the background when switching tabs? openWhenHidden: true keeps the connection alive but its not contitue fetching?