fix(query-core): refetch matched queries in resetQueries after reset#10891
fix(query-core): refetch matched queries in resetQueries after reset#10891chatman-media wants to merge 1 commit into
Conversation
resetQueries reset the matched queries first (mutating their status, e.g. error -> pending) and then re-ran the same filter to select refetch targets. State-dependent filters (e.g. predicate: status === 'error') no longer matched the now-changed queries, so they were never refetched and stayed pending. Snapshot the matched queries before resetting and refetch those directly. Closes TanStack#10705
|
Linter diff in the way? Review this PR in Change Stack to focus on meaningful changes and expand context only when needed. No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthrough
ChangesresetQueries state-dependent filter fix
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Closes #10705.
resetQueriesresets the matched queries first and then callsrefetchQuerieswith the samefilters:But
query.reset()mutates each query (statuserror→pending, etc.). So whenfiltersis state-dependent — e.g.predicate: (q) => q.state.status === 'error'— the now-reset queries no longer match, andrefetchQueriesrefetches nothing. They stay stuck inpendingforever.Fix: snapshot the matched queries before resetting them, then refetch exactly those (active ones) by identity — so re-filtering on mutated state can't drop them.
Test: added a
query-coretest — an active query that errors, thenresetQueries({ predicate: (q) => q.state.status === 'error' })must reset and refetch it (→success), not leave it pending.🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
resetQuerieswhen using state-dependent predicates. Previously, filtering queries by their current state (e.g.,errorstatus) and then callingresetQuerieswould reset the queries but fail to refetch the originally selected ones, as the state changes during reset. The fix captures matching queries before reset to ensure the correct queries are refetched.