feat: client-side SSE reconnect manager with visible banner#122
Merged
Conversation
Dropping the SSE stream left the tab silently frozen: the server-side re-bootstrap can only run once a reconnect reaches the server, but on a graceful clean-close deploy (or a persistent 403/session mismatch) Datastar exhausts its retries first and the tab never recovers — with zero user-visible feedback. Inject a small reconnect manager into every page (a Datastar data-init expression). It watches the datastar-fetch lifecycle: shows a "Reconnecting…" banner while the stream is retrying, and on retries-failed reloads the page — jittered to avoid a fleet stampeding the new pod, and bounded to 3 attempts via a sessionStorage counter so a down server can't pin a reload loop — to re-bootstrap a fresh stream and session. WithoutSSEReconnect() opts out. Server-side tests assert the manager is present (and the opt-out removes it); a browser-tagged chromedp test verifies it actually runs in Datastar (the IIFE evaluates, window.__viaRC is set), the banner appears on `retrying`, and `retries-failed` arms the bounded reload — verified locally against Chromium.
This was referenced Jun 11, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Critic panel finding #2 (blocker). Dropping the SSE stream left the tab silently frozen. The existing server-side re-bootstrap only runs once a reconnect reaches the server — but on a graceful clean-close deploy (or a persistent 403/session-mismatch) Datastar exhausts its retries first, so the tab never recovers and the user sees nothing.
Change
Inject a small reconnect manager into every page (a Datastar
data-initexpression, same mechanism as the existingbeforeunloadhook — no nonce/CSP change). It watches thedatastar-fetchlifecycle:retrying→ show a visible "Reconnecting…" banner (the freeze is no longer silent)started/finished→ clear the bannerretries-failed→ reload to re-bootstrap a fresh stream + session, jittered (500–2000ms, avoids a fleet stampeding the new pod) and bounded to 3 attempts via asessionStoragecounter so a down server can't pin a reload loop; after that it shows "Please refresh".Default on;
WithoutSSEReconnect()opts out. Covers both the clean-close deploy freeze and the session-403 case (both end in retries-failed).Why reload rather than re-arm the SSE from JS
Re-issuing Datastar's fetch-based SSE from a raw listener is fragile; a reload re-bootstraps the stream and the session deterministically — the robust path the design converged on.
Tests
data-initis present with thedatastar-fetch/retries-failed/reload branches;WithoutSSEReconnect()removes it.-tags browser, runs locally w/ Chromium — out of CI): verifies the injected IIFE actually evaluates in Datastar (window.__viaRC), the banner appears onretrying, andretries-failedarms the bounded reload. Verified green locally (stable across runs).Default
ci-check.shgreen (browser test excluded by build tag).