Skip to content

fix(query-core): refetch resetQueries matches after state-mutating reset - #11199

Open
MHJahanbakhsh wants to merge 1 commit into
TanStack:mainfrom
MHJahanbakhsh:fix/reset-queries-state-dependent-predicate
Open

fix(query-core): refetch resetQueries matches after state-mutating reset#11199
MHJahanbakhsh wants to merge 1 commit into
TanStack:mainfrom
MHJahanbakhsh:fix/reset-queries-state-dependent-predicate

Conversation

@MHJahanbakhsh

@MHJahanbakhsh MHJahanbakhsh commented Aug 16, 2026

Copy link
Copy Markdown

Summary

  • Fixes resetQueries method does not trigger refetch on errored queries #10705: resetQueries with a state-dependent filter (e.g. predicate: (query) => query.state.status === 'error') reset the matched queries but never refetched them.
  • reset() mutates query state before refetchQueries re-ran the same filters, so the intended queries no longer matched and stayed stuck in pending.
  • Snapshot the matched query set before resetting, then refetch exactly those queries (still respecting filters.type, defaulting to active).

Test plan

  • Added regression test covering success- and error-status predicates
  • pnpm --filter @tanstack/query-core exec vitest run src/__tests__/queryClient.test.tsx -t resetQueries (5 passed)

Summary by CodeRabbit

  • Bug Fixes
    • Fixed resetQueries so state-based filters are evaluated before queries are reset.
    • Ensured only the queries that originally matched the filters are refetched.
    • Preserved the configured refetch behavior, including query type selection.

Snapshot the matched query set before reset() so state-dependent filters
(e.g. status === 'error') still refetch the intended queries.

Fixes TanStack#10705
@coderabbitai

coderabbitai Bot commented Aug 16, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 38091631-6ead-4a14-a413-d831ee873077

📥 Commits

Reviewing files that changed from the base of the PR and between 4446c3a and 3a774e5.

📒 Files selected for processing (3)
  • .changeset/reset-queries-state-predicate.md
  • packages/query-core/src/__tests__/queryClient.test.tsx
  • packages/query-core/src/queryClient.ts

Included review availability: Your plan includes up to 10 reviews per rolling hour; 9 remain after this review.


📝 Walkthrough

Walkthrough

resetQueries now snapshots predicate matches before resetting query state, then refetches only those queries. Tests cover successful and errored queries. A patch changeset documents the correction.

Changes

resetQueries predicate handling

Layer / File(s) Summary
Snapshot matches and validate selective refetch
packages/query-core/src/queryClient.ts, packages/query-core/src/__tests__/queryClient.test.tsx, .changeset/reset-queries-state-predicate.md
resetQueries retains pre-reset query matches and refetches that snapshot. The refetch type uses the configured filter type or active. Tests verify selective refetching for successful and errored queries. A patch changeset documents the fix.

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

Merge Risk: ⚪ Minimal · up to 3a774

This change preserves the queries matched before reset so state-dependent filters are refetched as intended; the localized behavior fix and regression coverage leave no actionable merge-blocking risk beyond normal checks and review.

Possibly related PRs

Suggested reviewers: sukvvon

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly identifies the query-core fix and the state-mutating refetch behavior.
Description check ✅ Passed The description explains the bug, fix, and regression test, but it omits the repository template headings and checklist details.
Linked Issues check ✅ Passed The implementation snapshots pre-reset matches and refetches them, resolving issue #10705 while preserving active-type behavior.
Out of Scope Changes check ✅ Passed The changeset, implementation, and regression test directly support the resetQueries fix described in issue #10705.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ 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.

resetQueries method does not trigger refetch on errored queries

1 participant