Skip to content
Source
Sign inSign up
TanStack/query

fix(query-core): handle the rejection of paused refetches in 'refetchQueries' with 'throwOnError' #12442

Mergedlazerg(GitHub profile, opens in a new tab)merged 4 commits intomain fromrefs/pull/12442/headmerged by TkDodo View on GitHub

🎯 Changes

When a query is paused offline, refetchQueries returns Promise.resolve() for it instead of its fetch promise. With throwOnError: true that fetch promise had no .catch, so cancelling the paused fetch later (for example with queryClient.clear()) caused an unhandled CancelledError, even though the caller awaited refetchQueries.

The paused fetch promise now gets the same .catch(noop) as the non-throwOnError case. The returned promise still resolves right away for paused queries.

Fixes #12441

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with pnpm run test:pr, or these tests do not apply to this pull request.
  • I have followed the AI contribution policy and fully understand the code in this pull request, including any code generated with AI assistance.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

Summary by CodeRabbit

  • Bug Fixes
    • Paused query refetches no longer produce unhandled cancellation errors when the client is cleared. These refetches do not delay the returned promise, and later errors are handled safely, including when throwOnError is enabled. Refetches that were not paused when started retain their existing throwOnError behavior, preventing unexpected rejection events during cancellation.
    1. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 Changeset detected

      Latest commit: 82376d34ee08149be7ff81c359ed7a8ce5cf04b5

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 24 packages
      NameType
      @tanstack/query-corePatch
      @tanstack/angular-query-experimentalPatch
      @tanstack/lit-queryPatch
      @tanstack/preact-queryPatch
      @tanstack/query-async-storage-persisterPatch
      @tanstack/query-broadcast-client-experimentalPatch
      @tanstack/query-devtoolsPatch
      @tanstack/query-persist-client-corePatch
      @tanstack/query-sync-storage-persisterPatch
      @tanstack/react-queryPatch
      @tanstack/solid-queryPatch
      @tanstack/svelte-queryPatch
      @tanstack/vue-queryPatch
      @tanstack/preact-query-devtoolsPatch
      @tanstack/preact-query-persist-clientPatch
      @tanstack/react-query-devtoolsPatch
      @tanstack/solid-query-devtoolsPatch
      @tanstack/svelte-query-devtoolsPatch
      @tanstack/vue-query-devtoolsPatch
      @tanstack/react-query-persist-clientPatch
      @tanstack/solid-query-persist-clientPatch
      @tanstack/svelte-query-persist-clientPatch
      @tanstack/react-query-next-experimentalPatch
      @tanstack/eslint-plugin-queryPatch

      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

    2. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      Important

      Review skipped

      Review was skipped as selected files did not have any reviewable changes.

      Run configuration
      Commits

      Reviewing files that changed from the base of the PR and between ba96027b0860c7ed3524b1e06604ca24c788e781 and 82376d34ee08149be7ff81c359ed7a8ce5cf04b5.

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • Trigger review

      No actionable comments were generated in the recent review.

      Recent review info
      Run configuration
      Commits

      Reviewing files that changed from the base of the PR and between 2b45fed82b51264abb5d93bddcd7e84cfa114a4d and ba96027b0860c7ed3524b1e06604ca24c788e781.

      Files selected for processing: 1
      • packages/query-core/src/queryClient.ts

      Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 7 remain after this review.

      Walkthrough

      refetchQueries handles rejections from initially paused fetches, including when throwOnError is true. Its returned promise resolves without waiting for those fetches. A regression test checks that clearing the client after an offline refetch does not emit an unhandled rejection.

      Changes: Paused refetch handling

      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: Passed 5
      Check nameStatusExplanation
      Title checkPassedThe title clearly and concisely identifies the main change: handling rejected paused refetches in refetchQueries when throwOnError is enabled.
      Description checkPassedThe description explains the problem, the implementation, the preserved behavior, the linked issue, checklist completion, testing, and release impact. It includes the required changeset information.
      Linked Issues checkPassedIssue #12441 requires an observer for a paused fetch rejection while refetchQueries may resolve immediately. QueryClient.refetchQueries now applies promise.catch(noop) when the fetch is initiall…
      Out of Scope Changes checkPassedThe changes contain the targeted queryClient.ts fix, its regression test, and a patch changeset for @tanstack/query-core. These changes support Issue #12441. No unrelated change is shown.
      Docstring CoveragePassedNo 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. Documentat…
      Full details: Linked Issues check

      Explanation

      Issue #12441 requires an observer for a paused fetch rejection while refetchQueries may resolve immediately. QueryClient.refetchQueries now applies promise.catch(noop) when the fetch is initially paused and still returns Promise.resolve() for that query. The regression test covers offline pause, throwOnError: true, queryClient.clear(), and the absence of an unhandledRejection event.

      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.

      Share
    3. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit 82376d34ee08149be7ff81c359ed7a8ce5cf04b5

      CommandStatusDurationResult
      nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded7m 10sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded22sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-11-01 12:49:19 UTC

    4. More templates

      @tanstack/angular-query-experimental

      npm i https://pkg.pr.new/@tanstack/angular-query-experimental@12442

      @tanstack/eslint-plugin-query

      npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@12442

      @tanstack/lit-query

      npm i https://pkg.pr.new/@tanstack/lit-query@12442

      @tanstack/preact-query

      npm i https://pkg.pr.new/@tanstack/preact-query@12442

      @tanstack/preact-query-devtools

      npm i https://pkg.pr.new/@tanstack/preact-query-devtools@12442

      @tanstack/preact-query-persist-client

      npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@12442

      @tanstack/query-async-storage-persister

      npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@12442

      @tanstack/query-broadcast-client-experimental

      npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@12442

      @tanstack/query-core

      npm i https://pkg.pr.new/@tanstack/query-core@12442

      @tanstack/query-devtools

      npm i https://pkg.pr.new/@tanstack/query-devtools@12442

      @tanstack/query-persist-client-core

      npm i https://pkg.pr.new/@tanstack/query-persist-client-core@12442

      @tanstack/query-sync-storage-persister

      npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@12442

      @tanstack/react-query

      npm i https://pkg.pr.new/@tanstack/react-query@12442

      @tanstack/react-query-devtools

      npm i https://pkg.pr.new/@tanstack/react-query-devtools@12442

      @tanstack/react-query-next-experimental

      npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@12442

      @tanstack/react-query-persist-client

      npm i https://pkg.pr.new/@tanstack/react-query-persist-client@12442

      @tanstack/solid-query

      npm i https://pkg.pr.new/@tanstack/solid-query@12442

      @tanstack/solid-query-devtools

      npm i https://pkg.pr.new/@tanstack/solid-query-devtools@12442

      @tanstack/solid-query-persist-client

      npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@12442

      @tanstack/svelte-query

      npm i https://pkg.pr.new/@tanstack/svelte-query@12442

      @tanstack/svelte-query-devtools

      npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@12442

      @tanstack/svelte-query-persist-client

      npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@12442

      @tanstack/vue-query

      npm i https://pkg.pr.new/@tanstack/vue-query@12442

      @tanstack/vue-query-devtools

      npm i https://pkg.pr.new/@tanstack/vue-query-devtools@12442

      commit: 82376d3

    5. TkDodo merged thise69cac6

    6. TkDodo closed this

Sign in to join this conversation.