From f8d89bc2729e313836a0a19aa9a260fa520df071 Mon Sep 17 00:00:00 2001 From: Scott Idem Date: Thu, 26 Mar 2026 23:44:12 -0400 Subject: [PATCH] fix: close SSE connection cleanly on page navigation beforeunload closes the EventSource explicitly so the browser doesn't log "connection interrupted while page was loading". onerror handler suppresses auto-reconnect noise if the connection temporarily drops. Co-Authored-By: Claude Sonnet 4.6 --- cortex/static/app.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cortex/static/app.js b/cortex/static/app.js index 0288d18..db5b26e 100644 --- a/cortex/static/app.js +++ b/cortex/static/app.js @@ -1080,6 +1080,13 @@ // ── Real-time Talk updates (SSE) ───────────────────────────── const evtSource = new EventSource('/events'); + // Close cleanly on navigation so the browser doesn't log "connection interrupted" + window.addEventListener('beforeunload', () => evtSource.close()); + + evtSource.onerror = () => { + // EventSource auto-reconnects — nothing to do; suppress console noise + }; + evtSource.onmessage = (e) => { let data; try { data = JSON.parse(e.data); } catch { return; }