From 7bc5a15f4ad97247edeca73bc1ccca534788e457 Mon Sep 17 00:00:00 2001 From: Ray Andrew Date: Sun, 15 Feb 2026 05:28:01 -0600 Subject: [PATCH] feat(dashboard): improve EventSource connection handling with cleanup on page unload --- llm-gateway/internal/dashboard/templates/layout.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) 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) {