Skip to content

feat(frontend): add SSE recovery banner with reconnect countdown - #387

Merged
VarshithReddy2006 merged 1 commit into
VarshithReddy2006:mainfrom
Anshuu2004:feat/issue-364-sse-recovery-banner
Nov 17, 2026
Merged

VarshithReddy2006 merged 1 commit into
VarshithReddy2006:mainfrom
Anshuu2004:feat/issue-364-sse-recovery-banner

Conversation

@Anshuu2004

Copy link
Copy Markdown
Contributor

Summary

When the SSE connection drops the user currently gets no feedback at all. This adds a small status banner with a retry countdown and a Reconnect Now button, and refreshes the runtime state once the stream is back.

Closes #364

What changed

  • RecoveryOverlay.tsx: new ConnectionRecoveryBanner (rendered by RecoveryOverlay next to the existing comeback dialog, which is unchanged).
    • role="status" + aria-live="polite" region that stays mounted so screen readers pick up changes. The per-second countdown is aria-hidden so it does not get announced every second.
    • "Reconnecting to live server... Next attempt in Xs" while a retry is scheduled, button disabled while an attempt is running.
    • "Live updates paused. We could not reach the server." plus Reconnect Now once useSse gave up (5 consecutive failures).
    • "Connected!" for 1.5s after recovery, then it animates out. On recovery it invalidates the ['runtime-state'] query (the hook behind GET /runtime-state).
    • Only shown after a real drop, so the first connect after page load never flashes a banner. Not rendered for signed-out users.
  • useSse.ts:
    • nextReconnectAt (epoch ms) in the store and in the hook result, set in scheduleReconnect and cleared when the timer fires, on open and on disconnect.
    • exported reconnectNow(): cancels the pending backoff timer and connects right away. No-op while connected or already connecting (double click opens one stream). After the hook gave up it also resets the failure counter and the degraded flag so the manual retry gets a fresh budget.
    • Bug fix I had to make for the banner to work at all: getSnapshot returned the same mutated store object, and useSyncExternalStore only re-renders when the snapshot identity changes, so connectionStatus from useSse() never updated on its own. emitChange now takes a fresh copy of the store as the snapshot.

How I tested

From frontend/, one file at a time:

npx vitest run src/features/realtime/__tests__/RecoveryOverlay.test.tsx   # 10 passed
npx vitest run src/hooks/useSse.reconnect.test.ts                          # 5 passed
npx vitest run src/hooks/useSse.handshake.test.ts                          # 3 passed (existing)
npx vitest run src/features/realtime/RealtimeAccessibility.test.tsx        # 3 passed (existing)
npx vitest run src/__tests__/realtime/sse-manager.test.ts                  # 19 passed (existing)
npx vitest run src/hooks/useDsaData.test.tsx                               # 1 passed (existing)

With the two source files stashed the new tests fail (9 of 10 in RecoveryOverlay.test.tsx, 5 of 5 in useSse.reconnect.test.ts). The one that passes on main is the "comeback dialog still renders" regression guard. Reverting only the getSnapshot fix makes the "exposes when the next attempt happens" hook test fail.

tsc --noEmit -p tsconfig.app.json shows no errors in the touched files (the remaining errors are unrelated missing modules in my local node_modules).

Not tested / notes

  • Not clicked through in a real browser with DevTools offline, only jsdom + fake timers. framer-motion is mocked in the component test because exit animations do not finish under fake timers.
  • I left the offline action queue out on purpose (nothing like it exists yet; this was in my claim comment). The issue mentions it, so "pending optimistic actions are reconciled" is only covered by the runtime-state refetch for now.
  • The issue says /api/v2/runtime/state; on main the hook calls GET /runtime-state, so that is what gets invalidated.
  • ESLint could not be run in my environment (config fails to load against my local node_modules).

Show a polite status banner when the realtime connection drops, with a
countdown to the next retry, a Reconnect Now button, a short Connected!
message on recovery and a refetch of the runtime-state query.

useSse now exposes nextReconnectAt and a reconnectNow() helper. Its store
snapshot is also a fresh copy per change now, because the in-place mutated
object meant useSyncExternalStore never re-rendered subscribers.

Closes VarshithReddy2006#364

Signed-off-by: Abhishek <abhishekcse2004@gmail.com>
@VarshithReddy2006 VarshithReddy2006 added enhancement New feature or request help wanted Extra attention is needed nsoc26 level2 5 points - UI, frontend components, layouts, styling, and page-level changes. labels Nov 16, 2026
@VarshithReddy2006
VarshithReddy2006 merged commit 1981a3e into VarshithReddy2006:main Nov 17, 2026
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request help wanted Extra attention is needed level2 5 points - UI, frontend components, layouts, styling, and page-level changes. nsoc26

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(frontend,m10): build RecoveryOverlay with exponential backoff and pending action queue during SSE disconnects

2 participants