Skip to content

fix(interface): prevent refresh and reconnect banner on iOS app switch#606

Open
ibhagwan wants to merge 2 commits into
spacedriveapp:mainfrom
ibhagwan:fix/ui-reconnect-refresh
Open

fix(interface): prevent refresh and reconnect banner on iOS app switch#606
ibhagwan wants to merge 2 commits into
spacedriveapp:mainfrom
ibhagwan:fix/ui-reconnect-refresh

Conversation

@ibhagwan

@ibhagwan ibhagwan commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Disable React Query polling and focus refetch so backgrounding the app

does not trigger data refreshes when the tab regains focus.

Add a visibility-aware EventSource handler that closes the SSE

connection cleanly on hide and reconnects immediately on show, skipping

the exponential backoff. Errors from stale/closed connections are ignored.

onReconnect only fires after genuine error recovery, not visibility-driven

reconnects.

Note

Summary: Prevents unnecessary data refreshes and reconnection banners when switching apps on iOS or backgrounding the browser tab. The PR disables React Query's automatic refetching on window focus and adds a visibility listener to the EventSource connection that cleanly closes on tab hide and immediately reconnects on show, bypassing exponential backoff delays.

Written by Tembo for commit a54d6f44. This will update automatically on new commits.

@coderabbitai

coderabbitai Bot commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b24ee915-ddf5-44bb-bd2d-ec35ba175f10

📥 Commits

Reviewing files that changed from the base of the PR and between 7788763 and 67a8639.

📒 Files selected for processing (1)
  • interface/src/hooks/useEventSource.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • interface/src/hooks/useEventSource.ts

Walkthrough

React Query now disables window-focus and interval refetching. useEventSource adds reconnect tracking, stale-instance error handling, and a visibilitychange listener for hidden-tab reconnect behavior.

Changes

SSE Visibility Handling and Query Config

Layer / File(s) Summary
Disable React Query refetching
interface/src/App.tsx
defaultOptions.queries sets refetchOnWindowFocus: false and refetchInterval: false.
Reconnect state handling
interface/src/hooks/useEventSource.ts
connect() always transitions to "connecting". onopen clears the reconnect flag, resets retry delay, and calls onReconnect only after an error-driven reconnect. onerror ignores stale EventSource instances and marks the current one for reconnect tracking.
visibilitychange handling
interface/src/hooks/useEventSource.ts
A visibility listener closes and clears the EventSource while hidden, then resets retry delay and reconnects when visible again; the added note describes hidden-tab SSE freezes on mobile browsers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: preventing refreshes and reconnect banners during iOS app switching.
Description check ✅ Passed The description matches the changeset by describing React Query refetch changes and visibility-aware EventSource reconnect behavior.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Comment thread interface/src/hooks/useEventSource.ts Outdated

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@interface/src/hooks/useEventSource.ts`:
- Around line 54-60: The reconnect path in useEventSource is losing the “error
backoff happened” signal when the app is hidden and the retry timer is cleared,
so onReconnect is skipped after a foreground reconnect. Track error-reconnect
state separately from retryDelayRef in useEventSource (for example, a dedicated
ref/flag that is set when backoff starts and cleared only after onopen handles
it), and use that flag in the onopen handler instead of checking
retryDelayRef.current. Make sure the cleanup/reset logic around the retry timer
(the code around the retry delay reset and the onopen callback) preserves this
flag across app switches so missed-event resync still fires.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c49478a4-cc00-4d1e-89a6-702cd9a716f9

📥 Commits

Reviewing files that changed from the base of the PR and between ac52277 and a54d6f4.

📒 Files selected for processing (2)
  • interface/src/App.tsx
  • interface/src/hooks/useEventSource.ts

Comment thread interface/src/hooks/useEventSource.ts
Disable React Query polling and focus refetch so backgrounding the app

does not trigger data refreshes when the tab regains focus.

Add a visibility-aware EventSource handler that closes the SSE

connection cleanly on hide and reconnects immediately on show, skipping

the exponential backoff. Errors from stale/closed connections are ignored.

onReconnect only fires after genuine error recovery, not visibility-driven

reconnects.
@ibhagwan ibhagwan force-pushed the fix/ui-reconnect-refresh branch from 20de0b8 to 7788763 Compare June 29, 2026 00:44

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@interface/src/hooks/useEventSource.ts`:
- Around line 60-73: The useEventSource onopen handler is updating reconnect
state for stale EventSource instances, which can overwrite the real connection
state and suppress a needed resync. In useEventSource, add the same
current-source guard used by onerror before touching pendingErrorReconnectRef,
retryDelayRef, or setConnectionState, and only run onReconnectRef.current?.()
when the open event belongs to the active source.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 2955321a-47c0-4b95-b9b5-1b03e90aa7dd

📥 Commits

Reviewing files that changed from the base of the PR and between 20de0b8 and 7788763.

📒 Files selected for processing (2)
  • interface/src/App.tsx
  • interface/src/hooks/useEventSource.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • interface/src/App.tsx

Comment thread interface/src/hooks/useEventSource.ts
…n SSE hook

The visibility handler resets retryDelayRef when the app returns to the

foreground so reconnects are immediate. This caused onReconnect to be skipped

after a foreground reconnect because the code used retryDelayRef as the

error-reconnect signal.

Add a dedicated pendingErrorReconnectRef that is set in onerror and cleared

in onopen after handling it. This flag survives visibility changes so

missed-event re-sync still fires when a foreground reconnect recovers from

a prior connection error.

Refs: interface/src/hooks/useEventSource.ts
@ibhagwan ibhagwan force-pushed the fix/ui-reconnect-refresh branch from 7788763 to 67a8639 Compare June 29, 2026 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant