feat(dashboard): improve EventSource connection handling with cleanup on page unload
This commit is contained in:
parent
9ea3274ade
commit
7bc5a15f4a
1 changed files with 5 additions and 5 deletions
|
|
@ -325,17 +325,17 @@ window.matchMedia('(prefers-color-scheme: light)').addEventListener('change', fu
|
|||
source.onerror = function() {
|
||||
source.close();
|
||||
source = null;
|
||||
// Exponential backoff, max 30s
|
||||
setTimeout(connect, retryDelay);
|
||||
retryDelay = Math.min(retryDelay * 2, 30000);
|
||||
};
|
||||
}
|
||||
|
||||
connect();
|
||||
// Reconnect on HTMX page navigation (in case connection was lost)
|
||||
document.body.addEventListener('htmx:pushedIntoHistory', function() {
|
||||
if (!source || source.readyState === EventSource.CLOSED) connect();
|
||||
// Close cleanly on page unload to avoid browser "interrupted" errors
|
||||
window.addEventListener('beforeunload', function() {
|
||||
if (source) { source.close(); source = null; }
|
||||
});
|
||||
|
||||
connect();
|
||||
})();
|
||||
// Update active sidebar link on HTMX navigation
|
||||
document.body.addEventListener('htmx:pushedIntoHistory', function(e) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue