fix(interface): prevent refresh and reconnect banner on iOS app switch#606
fix(interface): prevent refresh and reconnect banner on iOS app switch#606ibhagwan wants to merge 2 commits into
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
WalkthroughReact Query now disables window-focus and interval refetching. ChangesSSE Visibility Handling and Query Config
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
interface/src/App.tsxinterface/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.
20de0b8 to
7788763
Compare
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
interface/src/App.tsxinterface/src/hooks/useEventSource.ts
🚧 Files skipped from review as they are similar to previous changes (1)
- interface/src/App.tsx
…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
7788763 to
67a8639
Compare
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.