GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — fix(query-core): keep retrying while unfocused when refetchIntervalInBackground is true by makoto-developer · Pull Request #11119 · TanStack/query Conversation
|
|
Caution Review failedThe pull request is closed. ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
📝 WalkthroughWalkthrough
ChangesBackground retry continuation
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant QueryFetch
participant Retryer
participant FocusManager
QueryFetch->>Retryer: Pass refetchIntervalInBackground
Retryer->>FocusManager: Check focus state
FocusManager-->>Retryer: Page is unfocused
Retryer->>Retryer: Continue retry when background refetch is enabled
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
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 `@packages/query-core/src/__tests__/query.test.tsx`:
- Around line 108-143: Update the test around queryClient.fetchQuery so
visibilityMock.mockRestore() always runs in a finally block. Await the fetch
promise directly within try, perform the existing result assertion after it
resolves, and preserve the retry behavior and expectations.
Fix all unresolved CodeRabbit comments on this PR:
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 898f080c-f566-4902-80ae-41947e0701aa
.changeset/quiet-retries-keep-running.mdpackages/query-core/src/__tests__/query.test.tsxpackages/query-core/src/query.tspackages/query-core/src/retryer.tspackages/query-core/src/types.ts
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| it('should keep retrying while unfocused when refetchIntervalInBackground is true', async () => { | ||
| const key = queryKey() | ||
|
|
||
| // make page unfocused | ||
| const visibilityMock = mockVisibilityState('hidden') | ||
|
|
||
| let count = 0 | ||
| let result | ||
|
|
||
| const promise = queryClient.fetchQuery({ | ||
| queryKey: key, | ||
| queryFn: () => { | ||
| count++ | ||
|
|
||
| if (count === 3) { | ||
| return `data${count}` | ||
| } | ||
|
|
||
| throw new Error(`error${count}`) | ||
| }, | ||
| retry: 3, | ||
| retryDelay: 1, | ||
| refetchIntervalInBackground: true, | ||
| }) | ||
|
|
||
| promise.then((data) => { | ||
| result = data | ||
| }) | ||
|
|
||
| // Retries proceed even though the page stays unfocused | ||
| await vi.advanceTimersByTimeAsync(50) | ||
| expect(result).toBe('data3') | ||
|
|
||
| visibilityMock.mockRestore() | ||
| }) | ||
|
|
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
🩺 Stability & Availability | 🟡 Minor | ⚡ Quick win
Restore the visibility mock in a finally block.
If the fetch or assertion fails, mockRestore() is skipped and can contaminate subsequent tests in the same worker. Await the promise directly inside try/finally.
- let result - const promise = queryClient.fetchQuery({ ... }) - promise.then((data) => { - result = data - }) - - await vi.advanceTimersByTimeAsync(50) - expect(result).toBe('data3') - - visibilityMock.mockRestore() + try { + await vi.advanceTimersByTimeAsync(50) + await expect(promise).resolves.toBe('data3') + } finally { + visibilityMock.mockRestore() + }
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| it('should keep retrying while unfocused when refetchIntervalInBackground is true', async () => { | |
| const key = queryKey() | |
| // make page unfocused | |
| const visibilityMock = mockVisibilityState('hidden') | |
| let count = 0 | |
| let result | |
| const promise = queryClient.fetchQuery({ | |
| queryKey: key, | |
| queryFn: () => { | |
| count++ | |
| if (count === 3) { | |
| return `data${count}` | |
| } | |
| throw new Error(`error${count}`) | |
| }, | |
| retry: 3, | |
| retryDelay: 1, | |
| refetchIntervalInBackground: true, | |
| }) | |
| promise.then((data) => { | |
| result = data | |
| }) | |
| // Retries proceed even though the page stays unfocused | |
| await vi.advanceTimersByTimeAsync(50) | |
| expect(result).toBe('data3') | |
| visibilityMock.mockRestore() | |
| }) | |
| it('should keep retrying while unfocused when refetchIntervalInBackground is true', async () => { | |
| const key = queryKey() | |
| // make page unfocused | |
| const visibilityMock = mockVisibilityState('hidden') | |
| let count = 0 | |
| const promise = queryClient.fetchQuery({ | |
| queryKey: key, | |
| queryFn: () => { | |
| count++ | |
| if (count === 3) { | |
| return `data${count}` | |
| } | |
| throw new Error(`error${count}`) | |
| }, | |
| retry: 3, | |
| retryDelay: 1, | |
| refetchIntervalInBackground: true, | |
| }) | |
| try { | |
| await vi.advanceTimersByTimeAsync(50) | |
| await expect(promise).resolves.toBe('data3') | |
| } finally { | |
| visibilityMock.mockRestore() | |
| } | |
| }) |
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@packages/query-core/src/__tests__/query.test.tsx` around lines 108 - 143,
Update the test around queryClient.fetchQuery so visibilityMock.mockRestore()
always runs in a finally block. Await the fetch promise directly within try,
perform the existing result assertion after it resolves, and preserve the retry
behavior and expectations.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
View your CI Pipeline Execution ↗ for commit 3140ee5
☁️ Nx Cloud last updated this comment at |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
we actually decided on not doing this: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
Polling Stops with refetchIntervalInBackground and Retry When Tab Is Inactive
There was an error while loading. Please reload this page.