Skip to content

fix(query-core): release the retryer once a fetch settles - #11163

Open
codebytere-ant wants to merge 1 commit into
TanStack:mainfrom
codebytere-ant:release-settled-retryer
Open

fix(query-core): release the retryer once a fetch settles#11163
codebytere-ant wants to merge 1 commit into
TanStack:mainfrom
codebytere-ant:release-settled-retryer

Conversation

@codebytere-ant

@codebytere-ant codebytere-ant commented Aug 9, 2026

Copy link
Copy Markdown

🎯 Changes

Query.fetch() leaves #retryer set after the fetch settles. The retryer's resolved promise still holds the raw result of that fetch, so once a query has refetched it holds its data twice: the structurally shared objects in state.data, plus the fresh result the promise resolved with. It also means reset() and removeQueries() don't free the data while anything still points at the query.

This clears #retryer in the existing finally once the fetch has settled. The identity check is there so a fetch started synchronously from a cache onSuccess/onSettled callback keeps its own retryer. The other readers of #retryer are already behind ?. or a fetchStatus check, so the only visible change is that query.promise is undefined after a fetch has settled instead of the settled promise.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm run test:pr.

🚀 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

    • Released query retry resources after fetches settle, queries reset, or queries are removed.
    • Prevented settled promises from retaining unnecessary fetch results.
    • Ensured callback-triggered refetches complete correctly after an initial fetch.
  • Release

    • Included in a patch release of the query core package.

A query kept its last retryer for life, and the settled promise holds that
fetch's raw result: a second full copy of the data once a refetch has been
structurally shared into state.data, and still held after reset() or removal.
@coderabbitai

coderabbitai Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Query.fetch now releases the settled retryer when it remains current. Tests cover callback-triggered refetches and confirm that the query promise is cleared after both fetches settle. A patch changeset documents the behavior.

Changes

Settled retryer release

Layer / File(s) Summary
Clear settled retryers
packages/query-core/src/query.ts
Query.fetch stores the retryer locally, starts that instance, and clears #retryer after settlement when it still references the settled retryer.
Validate retryer cleanup
packages/query-core/src/__tests__/query.test.tsx, .changeset/release-settled-retryer.md
Tests cover a callback-triggered refetch and verify that the query promise is cleared after both fetches resolve. The changeset records a patch release for @tanstack/query-core.

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

Possibly related PRs

  • TanStack/query#11119: Both PRs modify Query.fetch and query-core retryer behavior, but this PR releases settled retryers while that PR permits background retries.

Suggested reviewers: sukvvon

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
Title check ✅ Passed The title clearly and concisely describes the primary change: releasing the query-core retryer after fetch settlement.
Description check ✅ Passed The description covers the change, motivation, testing checklist, release impact, and generated changeset; the unselected test item is non-critical.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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

Comment @coderabbitai help to get the list of available commands.

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.

1 participant