feat(dashboard): improve EventSource connection handling with cleanup on page unload

This commit is contained in:
Ray Andrew 2026-02-15 05:28:01 -06:00
parent 9ea3274ade
commit 7bc5a15f4a
Signed by: rayandrew
SSH key fingerprint: SHA256:EUCV+qCSqkap8rR+p+zGjxHfKI06G0GJKgo1DIOniQY

View file

@ -325,17 +325,17 @@ window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', fu
source.onerror = function() { source.onerror = function() {
source.close(); source.close();
source = null; source = null;
// Exponential backoff, max 30s
setTimeout(connect, retryDelay); setTimeout(connect, retryDelay);
retryDelay = Math.min(retryDelay * 2, 30000); retryDelay = Math.min(retryDelay * 2, 30000);
}; };
} }
connect(); // Close cleanly on page unload to avoid browser "interrupted" errors
// Reconnect on HTMX page navigation (in case connection was lost) window.addEventListener('beforeunload', function() {
document.body.addEventListener('htmx:pushedIntoHistory', function() { if (source) { source.close(); source = null; }
if (!source || source.readyState === EventSource.CLOSED) connect();
}); });
connect();
})(); })();
// Update active sidebar link on HTMX navigation // Update active sidebar link on HTMX navigation
document.body.addEventListener('htmx:pushedIntoHistory', function(e) { document.body.addEventListener('htmx:pushedIntoHistory', function(e) {