Skip to content

fix(app): force SSE reconnect on tab refocus after long hidden duration - #19461

Closed
philstevenson wants to merge 1 commit into
anomalyco:devfrom
philstevenson:fix/web-ui-refresh-on-refocus
Closed

philstevenson wants to merge 1 commit into
anomalyco:devfrom
philstevenson:fix/web-ui-refresh-on-refocus

Conversation

@philstevenson

Copy link
Copy Markdown

Summary

  • Fix web UI not refreshing data when the tab is refocused after being hidden
  • Track when the tab becomes hidden and force SSE stream reconnect if either the event stream is stale or the tab was hidden longer than the heartbeat timeout (15s)

Problem

The onVisibility handler in global-sdk.tsx only checked Date.now() - lastEventAt < HEARTBEAT_TIMEOUT_MS when the tab regained focus. This missed the common scenario where:

  1. A heartbeat arrives at T=0
  2. User switches tabs at T=1s
  3. Browser freezes the tab's JS timers
  4. User returns at T=12s
  5. Date.now() - lastEventAt = 12s < 15s — handler does nothing
  6. The SSE connection may have silently died, but the client doesn't reconnect

Fix

Track hiddenAt on visibilitychange: hidden, then on visible force reconnect if either condition is true:

  • No SSE event received in 15s (original check)
  • Tab was hidden for 15s+ (new check — catches frozen-timer cases)

The downstream refresh flow (server.connected → queue.refresh() → bootstrap() + child directory re-bootstrap) already handles full state sync once the SSE reconnects. No other files need changes.

Testing

  • All 299 existing unit tests pass
  • Typecheck passes

The onVisibility handler only checked lastEventAt against a 15s threshold,
which missed cases where the tab was hidden long enough for the SSE
connection to silently die but lastEventAt still appeared recent. Track
when the tab was hidden and force reconnect if either the event stream
is stale or the tab was hidden longer than the heartbeat timeout.
@github-actions github-actions Bot added needs:compliance This means the issue will auto-close after 2 hours. needs:issue labels Mar 27, 2026
@github-actions

Copy link
Copy Markdown
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions

Copy link
Copy Markdown
Contributor

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

@github-actions

Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it was not updated to meet our contributing guidelines within the 2-hour window.

Feel free to open a new pull request that follows our guidelines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant