fix(query-core): refresh combined result after query-list notifications 🤖🤖🤖 #12646
main fromrefs/pull/12646/head·opened View on GitHubFixes #12626
🎯 Changes#
Pass the hashes for the active observers when combining notification results. An update from the previous query list now invalidates the cached combine before the next optimistic result.
Added a regression test and a patch changeset.
✅ Checklist#
- I followed the steps in the contributing guide.
-
pnpm run test:prcompleted successfully. The focused query-core tests, compile, oxlint, and formatting checks passed. The workspace-wide run could not complete because the filtered install left dependencies for unrelated packages unavailable. - I followed the AI contribution policy and understand the code in this pull request.
🚀 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 an issue where combined query results could become stale when query notifications arrived during an optimistic update to the query list. Combined results now stay consistent when switching between query lists, including when result transformations are applied.
- 1
Codex Review Summary: ✅ Completed
This comment shows the latest Codex review activity on this pull request.
Review Status Commit Review trigger 📝 Code Review ✅ Completed 2026-11-20T20:45:00.602728Z cf61ab6PR opened ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review" or "@codex security review".
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
pei711(GitHub profile, opens in a new tab) linked this to fix #12626
tanstack-source added labelsbug
No actionable comments were generated in the recent review.
Walkthrough
-
The notification path now passes current query hashes to combined-result memoization when a
combinefunction is configured. A regression test covers a query-list change followed by a notification, and a changeset declares a patch release.Changes: Combined result updates
Layer / File(s) Summary Notification hash tracking and regression coverage
packages/query-core/src/queriesObserver.ts,packages/query-core/src/__tests__/queriesObserver.test.tsx,.changeset/soft-bears-race.md#notifypasses the current matched query hashes to#combineResultwhencombineis configured. The regression test checks that a five-query optimistic result remains length five aftersetQueriesreceives the original three queries. The changeset declares a patch release for@tanstack/query-core.Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related PRs
- TanStack/query#12633: Passes observer query hashes to
#combineResultto address the same stale-result defect. - TanStack/query#12632: Applies the same notification hash change and targets the same regression scenario.
- TanStack/query#12638: Passes hashes for the observers combined by
#notifyto keep the cached hashes in sync.
Suggested reviewers:
sukvvon,tkdodo - TanStack/query#12633: Passes observer query hashes to
Merge Risk:
Minimal · up tocf61a-
This fixes stale combined results in useQueries when a notification arrives during an optimistic query-list change. The change is small and covered by a regression test, and no merge-blocking risk was found.
Pre-merge checks:
4-
Check name Status Explanation Title check The title names the fix (refreshing the combined result after query-list notifications) in query-core, which matches the changeset, the queriesObserver.ts change, and the linked issue #12626. The emoj…Description check The description follows the template. It has a Changes section that explains passing active observer hashes to the combine cache, and it links issue #12626. The checklist is filled in. It states that …Linked Issues check Issue #12626requires that a stablecombineinuseQueriesreturns a result that matches the current query list, even when an existing query updates beforesetQueriesruns. At the reviewed head, …Out of Scope Changes check All changes support issue #12626. The queriesObserver.ts change is the direct fix in#notify. The regression test covers the combine and hash-change behavior that the fix affects. The changeset declar…Full details: Title check
-
Explanation
The title names the fix (refreshing the combined result after query-list notifications) in query-core, which matches the changeset, the queriesObserver.ts change, and the linked issue
#12626. The emoji noise and the 78-character length are minor and do not change the meaning.
Full details: Description check
-
Explanation
The description follows the template. It has a Changes section that explains passing active observer hashes to the combine cache, and it links issue
#12626. The checklist is filled in. It states that a regression test and a patch changeset were added, which matches the diff summary. It also states that the full pnpm run test:pr run did not finish, and it gives the reason. The Release Impact boxes are marked correctly.
Full details: Linked Issues check
-
Explanation
Issue
#12626requires that a stablecombineinuseQueriesreturns a result that matches the current query list, even when an existing query updates beforesetQueriesruns. At the reviewed head,QueriesObserver.#notify(packages/query-core/src/queriesObserver.ts) now passesthis.#observerMatches.map(match => match.defaultedQueryOptions.queryHash)to#combineResultwhencombineis configured. This is the remediation the issue proposes. In the reported sequence, the notification from query list A sets#lastQueryHashesto A. The next render with list B then seesqueryHashesChanged === true, which forces recomputation from the 5 results. The change is the coding requirement. A regression test was added in packages/query-core/src/tests/queriesObserver.test.tsx (+51 lines). Per the supplied summary, it checks that the optimistic combined result keeps length five after the observer updates back to three queries. That scenario is related to, but not identical to, the issue's exact reproduction. The test was not run in this review. Thepnpm run test:prworkspace run was not completed according to the PR description. Repository file reads for the diff were unavailable, so the code evidence comes from the reviewed head file contents.
Full details: Out of Scope Changes check
-
Explanation
All changes support issue
#12626. The queriesObserver.ts change is the direct fix in#notify. The regression test covers the combine and hash-change behavior that the fix affects. The changeset declares a patch release for@tanstack/query-core, which matches the published code change. No unrelated files or behavior changes appear in the supplied summary. The summary lists only these three 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.
Recent review info-
Run configuration-
- Source mode: Auto
- Repository: TanStack/query
- Branch: main
- File: .coderabbit.yaml
- Commit: 8b2e8af
- Layers: Repository YAML
- Review profile: CHILL
- Plan: Advanced
- Run ID:
917124bd-4587-4bc7-b50d-15150579a2fb
Commits-
Reviewing files that changed from the base of the PR and between 8b2e8af0768c12500e914ac7055f007c65d8316a and cf61ab6c8674ae1c3edc09268e218abff1db528a.
Files selected for processing: 3-
.changeset/soft-bears-race.mdpackages/query-core/src/__tests__/queriesObserver.test.tsxpackages/query-core/src/queriesObserver.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
-
-
TkDodo closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: cf61ab6c8674ae1c3edc09268e218abff1db528a
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 26 packages
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