Repository navigation
fix(query-core): handle the rejection of paused refetches in 'refetchQueries' with 'throwOnError' - #12442
Conversation
…Queries' with 'throwOnError'
🦋 Changeset detectedLatest commit: 82376d3 The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Important Review skippedReview was skipped as selected files did not have any reviewable changes.
|
| Layer / File(s) | Summary |
|---|---|
Handle paused refetch rejections packages/query-core/src/queryClient.ts, packages/query-core/src/__tests__/queryClient.test.tsx, .changeset/paused-refetch-unhandled-rejection.md |
refetchQueries records whether each fetch is paused, handles rejection from paused fetches, and resolves their contribution immediately. The test covers an offline refetch followed by client cleanup. The changeset records the patch. |
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related issues
- TanStack/query#12441: The issue describes the same unhandled rejection after clearing a client with a paused refetch; this change handles that detached rejection.
Suggested reviewers: sukvvon, tkdodo
Merge Risk: 
Minimal · previous review ba960
-
The paused-refetch rejection handling and cleanup regression coverage present no identified merge-blocking risk.
Pre-merge checks: 
5
-
Full details: Linked Issues check
-
Explanation
Issue
#12441requires an observer for a paused fetch rejection whilerefetchQueriesmay resolve immediately.QueryClient.refetchQueriesnow appliespromise.catch(noop)when the fetch is initially paused and still returnsPromise.resolve()for that query. The regression test covers offline pause,throwOnError: true,queryClient.clear(), and the absence of anunhandledRejectionevent.
Full details: Docstring Coverage
-
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.
-
Finishing Touches
-
Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
|
View your CI Pipeline Execution ↗ for commit 82376d3
☁️ Nx Cloud last updated this comment at |
🎯 Changes
When a query is paused offline,
refetchQueriesreturnsPromise.resolve()for it instead of its fetch promise. WiththrowOnError: truethat fetch promise had no.catch, so cancelling the paused fetch later (for example withqueryClient.clear()) caused an unhandledCancelledError, even though the caller awaitedrefetchQueries.The paused fetch promise now gets the same
.catch(noop)as the non-throwOnErrorcase. The returned promise still resolves right away for paused queries.Fixes #12441
✅ Checklist
pnpm run test:pr, or these tests do not apply to this pull request.🚀 Release Impact
Summary by CodeRabbit
throwOnErroris enabled. Refetches that were not paused when started retain their existingthrowOnErrorbehavior, preventing unexpected rejection events during cancellation.