Skip to content

fix(query-core): skip pausing cancelled retries - #11537

Merged
TkDodo merged 3 commits into
TanStack:mainfrom
brennanbutler01:fix/cancelled-retry-pause
Nov 2, 2026
Merged

TkDodo merged 3 commits into
TanStack:mainfrom
brennanbutler01:fix/cancelled-retry-pause

Conversation

@brennanbutler01

@brennanbutler01 brennanbutler01 commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

🎯 Changes

A retry delay can expire after cancelQueries has already settled the fetch. If the client is offline or unfocused, that old continuation still calls onPause, changing the cancelled query from idle to paused. It can also overwrite a replacement fetch's status and prevent an inactive query from being garbage-collected.

Skip pausing once the retryer has settled. Adds deterministic fake-timer regressions for offline/unfocused cancellation, replacement-fetch status, garbage collection, and React with and without Strict Mode.

Reproduced on 5.101.2, stable 5.103.1 source, and main (bb9d313). All six new core/React regression cases failed before the fix. Afterward, 1,601 core assertions and 585 React tests pass. Searches found no matching active fix; #10291 handles initially paused fetches on unmount and #11342 handles silent-cancellation promise results, rather than delayed pause notifications.

✅ 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 fully understand the code in this pull request, including any code generated with AI assistance.

The full cross-framework test:pr run was not performed. Both affected packages passed test:lib, test:types, test:eslint, and test:build through Nx, including dependency builds. The compiler matrix covers TypeScript 5.6, 5.7, 5.8, 5.9, 6.0, and 7.0. Existing lint warnings are in unchanged code. Tested on Node 24.13.0.

Implemented and locally verified with AI assistance. The contributor-understanding checkbox is left for the author's review.

🚀 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
    • Fixed cancelled queries so an expired retry delay no longer pauses them when the app is offline or unfocused.
    • Replacement fetches can continue and resolve normally after a cancelled retry, even when the app is unfocused.
    • Cancelled queries with a configured garbage-collection timeout are removed from query state after that timeout, including after cancellation during a retry delay.

Check whether the retryer settled before its delayed continuation can
notify a pause. A cancelled retry must not overwrite a replacement
fetch status or prevent an inactive query from being collected.

Cover offline and unfocused retries, replacement fetches, garbage
collection, and React cancellation with and without Strict Mode.
Copilot AI lite review requested due to automatic review settings September 18, 2026 07:48
@coderabbitai

coderabbitai Bot commented Sep 18, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

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 9f6e59b and f67292a.

Files selected for processing: 4
  • packages/query-core/src/__tests__/query.test.tsx
  • packages/query-core/src/__tests__/retryer.test.tsx
  • packages/query-core/src/retryer.ts
  • packages/react-query/src/__tests__/useQuery.test.tsx

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

Walkthrough

The retryer now skips pausing when it has resolved during a retry delay. Tests cover cancelled retry behavior in query-core and React Query, including replacement fetches, garbage collection, and fetch status during focus changes.

Changes: Cancelled retry handling

Layer / File(s) Summary
Retry delay resolution guard
packages/query-core/src/retryer.ts, .changeset/cancelled-retry-pause.md
The retryer checks whether it has resolved before pausing after a retry delay. The changeset declares a patch release for @tanstack/query-core.
Cancellation behavior coverage
packages/query-core/src/__tests__/retryer.test.tsx, packages/query-core/src/__tests__/query.test.tsx, packages/react-query/src/__tests__/useQuery.test.tsx
Tests cover cancelled retryers, replacement fetches, garbage collection, and fetch status while focus changes.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Suggested reviewers: sukvvon, tkdodo

Merge Risk: Minimal · up to f6729

Cancelled retries no longer leave queries paused after settlement. No merge-blocking issue was identified.

Pre-merge checks: Passed 5
Check name Status Explanation
Title check Passed The title clearly and concisely describes the main change: preventing cancelled retries from pausing.
Description check Passed The description includes the required Changes, Checklist, and Release Impact sections. It explains the bug, fix, regression coverage, validation results, and changeset. It also transparently records t…
Docstring Coverage Passed 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. Documentat…
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.
Full details: Description check

Explanation

The description includes the required Changes, Checklist, and Release Impact sections. It explains the bug, fix, regression coverage, validation results, and changeset. It also transparently records that the full test:pr run was not performed and that the AI contribution checklist item remains unchecked.

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 4 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No unresolved review issues were identified.

Pull request overview

Fixes cancelled retry continuations incorrectly pausing settled queries, with core and React regression coverage.

Changes:

  • Skip pause notifications after retryer settlement.
  • Add cancellation, replacement-fetch, garbage-collection, and Strict Mode tests.
  • Add a query-core patch changeset.
File summaries
File Description
packages/react-query/src/__tests__/useQuery.test.tsx Tests React cancellation behavior with and without Strict Mode.
packages/query-core/src/retryer.ts Prevents settled retryers from pausing queries.
packages/query-core/src/__tests__/retryer.test.tsx Tests cancelled retry behavior.
packages/query-core/src/__tests__/query.test.tsx Tests replacement fetches and garbage collection.
.changeset/cancelled-retry-pause.md Documents the patch release.
Review details
  • Files reviewed: 5/5 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

…-pause

# Conflicts:
#	packages/query-core/src/retryer.ts
@changeset-bot

changeset-bot Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: f67292a

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

This PR includes changesets to release 24 packages
Name Type
@tanstack/query-core Patch
@tanstack/angular-query-experimental Patch
@tanstack/lit-query Patch
@tanstack/preact-query Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-broadcast-client-experimental Patch
@tanstack/query-devtools Patch
@tanstack/query-persist-client-core Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query Patch
@tanstack/solid-query Patch
@tanstack/svelte-query Patch
@tanstack/vue-query Patch
@tanstack/preact-query-devtools Patch
@tanstack/preact-query-persist-client Patch
@tanstack/react-query-devtools Patch
@tanstack/solid-query-devtools Patch
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch
@tanstack/react-query-persist-client Patch
@tanstack/solid-query-persist-client Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/react-query-next-experimental Patch
@tanstack/eslint-plugin-query Patch

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

@brennanbutler01

Copy link
Copy Markdown
Contributor Author

Could someone help me replace this PR from the rewritten branch? I rewrote the commits on my personal fork so the author and committer use my personal GitHub identity. The patch is unchanged, but this PR still shows the old head (9f6e59b). The rewritten branch is fix/cancelled-retry-pause-rewritten (58ef075). My personal account can’t create a replacement PR because I’m not a member of the TanStack org. Could someone with org access open a replacement from that branch or tell me the right way to proceed? I’ve left this PR open so the discussion stays here.

@nx-cloud

nx-cloud Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

View your CI Pipeline Execution ↗ for commit f67292a

Command Status Duration Result
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 25s View ↗
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 56s View ↗

☁️ Nx Cloud last updated this comment at 2026-11-02 20:16:33 UTC

@TkDodo TkDodo closed this Nov 2, 2026
@TkDodo TkDodo reopened this Nov 2, 2026
@pkg-pr-new

pkg-pr-new Bot commented Nov 2, 2026

Copy link
Copy Markdown
More templates

@tanstack/angular-query-experimental

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

@tanstack/eslint-plugin-query

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

@tanstack/lit-query

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

@tanstack/preact-query

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

@tanstack/preact-query-devtools

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

@tanstack/preact-query-persist-client

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

@tanstack/query-async-storage-persister

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

@tanstack/query-broadcast-client-experimental

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

@tanstack/query-core

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

@tanstack/query-devtools

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

@tanstack/query-persist-client-core

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

@tanstack/query-sync-storage-persister

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

@tanstack/react-query

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

@tanstack/react-query-devtools

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

@tanstack/react-query-next-experimental

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

@tanstack/react-query-persist-client

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

@tanstack/solid-query

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

@tanstack/solid-query-devtools

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

@tanstack/solid-query-persist-client

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

@tanstack/svelte-query

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

@tanstack/svelte-query-devtools

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

@tanstack/svelte-query-persist-client

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

@tanstack/vue-query

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

@tanstack/vue-query-devtools

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

commit: f67292a

@TkDodo
TkDodo merged commit 3f4de1b into TanStack:main Nov 2, 2026
12 of 14 checks passed
@github-actions github-actions Bot mentioned this pull request Nov 2, 2026
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.

4 participants