Close SSE connection nicely on navigating away from the page

This commit is contained in:
Ian Renton
2026-06-05 18:52:32 +01:00
parent 6938a8cc0a
commit 72360758ac
11 changed files with 31 additions and 23 deletions

View File

@@ -4,6 +4,14 @@ let restartSSEOnErrorTimeoutId;
// Table row count, to alternate shading
let rowCount = 0;
// Set up a listener to close the SSE connection nicely when we navigate away from the page, to prevent console errors
// and keep things nice and tidy for the server.
window.addEventListener('beforeunload', function() {
if (evtSource != null) {
evtSource.close();
}
});
// Load spots and populate the table.
function loadSpots() {
// If we have an ongoing SSE connection, stop it so it doesn't interfere with our reload