diff --git a/llm-gateway/internal/dashboard/templates/layout.html b/llm-gateway/internal/dashboard/templates/layout.html index aebd327..1b35132 100644 --- a/llm-gateway/internal/dashboard/templates/layout.html +++ b/llm-gateway/internal/dashboard/templates/layout.html @@ -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) {