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.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) {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue