GeezerVison is showing github.com — fix(query-core): fix combine not updating when queries change with stable reference by minseong0324 · Pull Request #9954 · TanStack/query
Conversation
minseong0324
commented
Dec 7, 2025
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
🎯 Changes
Fixes #8781
Problem
With stable combine, results lag one step behind when queries change.
This happens because getOptimisticResult runs before setQueries updates this.#result.
Solution
Pass queryHashes to #combineResult to detect query changes before this.#result is updated.
✅ 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
- Combined query results now reliably update when the set of queries changes (add/remove/replace), ensuring aggregated results stay accurate.
-
Tests
- Added coverage for dynamic query counts and stable combine behavior to prevent regressions.
-
Chores
- Release patch entry added documenting the fix.
✏️ Tip: You can customize this high-level summary in your review settings.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
changeset-bot
Bot
commented
Dec 7, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
🦋 Changeset detected
Latest commit: 4c928c0
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 19 packages
| Name |
Type |
| @tanstack/query-core |
Patch |
| @tanstack/angular-query-experimental |
Patch |
| @tanstack/query-async-storage-persister |
Patch |
| @tanstack/query-broadcast-client-experimental |
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/angular-query-persist-client |
Patch |
| @tanstack/react-query-persist-client |
Patch |
| @tanstack/solid-query-persist-client |
Patch |
| @tanstack/svelte-query-persist-client |
Patch |
| @tanstack/react-query-devtools |
Patch |
| @tanstack/react-query-next-experimental |
Patch |
| @tanstack/solid-query-devtools |
Patch |
| @tanstack/svelte-query-devtools |
Patch |
| @tanstack/vue-query-devtools |
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
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Dec 7, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
📝 Walkthrough
Walkthrough
Adds tracking of query hashes in QueriesObserver to detect structural changes and force re-evaluation of a stable combine function; updates optimistic result flow and tests to cover dynamic add/remove/replace scenarios and duplicate keys.
Changes
| Cohort / File(s) |
Summary |
Changeset \.changeset/swift-brooms-teach.md`` |
New changeset added: patch bump for @tanstack/query-core with description "fix stable combine reference not updating when queries change dynamically." |
Query Core Implementation \packages/query-core/src/queriesObserver.ts`` |
Adds private #lastQueryHashes?: string[]; threads query-hash computation through getOptimisticResult into #combineResult(queryHashes?); compares and updates #lastQueryHashes to trigger recompute when hashes change. Method signature of #combineResult updated. |
Query Core Tests \packages/query-core/src/tests/queriesObserver.test.tsx`` |
Adds tests exercising optimistic results and stable combine behavior across adding, removing, replacing queries, duplicate keys, and early-return update scenarios. |
React Query Tests \packages/react-query/src/tests/useQueries.test.tsx`` |
Adds a test ensuring useQueries with a stable combine reference returns correct results as the number of queries changes. |
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~45 minutes
Possibly related PRs
Suggested reviewers
Poem
🐰 I tracked the hashes, one by one,
So combines wake when queries run.
Adding, swapping, left or right,
The results now hop into sight.
A cheeky fix — makes everything fun! 🥕✨
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name |
Status |
Explanation |
Resolution |
| Docstring Coverage |
⚠️ Warning |
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. |
You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (4 passed)
| Check name |
Status |
Explanation |
| Title check |
✅ Passed |
The title accurately summarizes the main fix: ensuring the combine function updates when queries change with a stable reference. |
| Description check |
✅ Passed |
The description follows the template, explains the problem and solution clearly, and includes all required checklist items completed. |
| Linked Issues check |
✅ Passed |
The PR successfully addresses issue #8781 by detecting query changes via queryHashes before result updates, preventing the one-render lag with stable combine references. |
| Out of Scope Changes check |
✅ Passed |
All changes are scoped to fixing the stable combine reference bug: test additions, queryHashes tracking implementation, and changeset file. |
✨ Finishing touches
📜 Recent review details
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 89db791 and 291afec.
📒 Files selected for processing (1)
packages/query-core/src/queriesObserver.ts
🧰 Additional context used
🧬 Code graph analysis (1)
packages/query-core/src/queriesObserver.ts (1)
packages/query-core/src/types.ts (1)
QueryObserverResult (903-908)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (4)
packages/query-core/src/queriesObserver.ts (4)
46-46: LGTM!
The new #lastQueryHashes field follows the naming convention of other caching fields (#lastCombine, #lastResult) and is appropriately typed as optional.
184-191: LGTM! Correctly captures query state before #result is updated.
Computing queryHashes from the freshly matched observers and passing them to #combineResult ensures that structural changes to the queries array are detected immediately during the optimistic result phase, before setQueries updates this.#result.
222-240: LGTM! The query hash comparison logic correctly detects structural changes.
The implementation properly handles the key scenarios:
- First call:
#lastQueryHashes is undefined → queryHashesChanged is false, but #combinedResult is also undefined, so recomputation happens anyway.
- Subsequent optimistic calls: Both hash arrays are defined, enabling detection of query additions/removals/replacements.
#notify() path: Called without queryHashes, so #lastQueryHashes is preserved. This is correct since #notify() runs after setQueries has already updated #result, and the this.#result !== this.#lastResult check handles that path.
295-309: Verify the intentional asymmetry between update paths.
The #notify() method calls #combineResult without queryHashes, which is correct because:
- By the time
#notify() executes, setQueries has already updated this.#result
- Changes are detected via
this.#result !== this.#lastResult
This intentional asymmetry preserves #lastQueryHashes for subsequent optimistic calls. Just confirming this design choice is understood for future maintainers.
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 and usage tips.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
nx-cloud
Bot
commented
Dec 7, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
View your CI Pipeline Execution ↗ for commit 4c928c0
| Command |
Status |
Duration |
Result |
nx affected --targets=test:sherif,test:knip,tes... |
✅ Succeeded |
56s |
View ↗ |
☁️ Nx Cloud last updated this comment at 2026-01-16 15:24:20 UTC
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
pkg-pr-new
Bot
commented
Dec 7, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
More templates
@tanstack/angular-query-experimental
npm i https://pkg.pr.new/@tanstack/angular-query-experimental@9954
@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@9954
@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@9954
@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@9954
@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@9954
@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@9954
@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@9954
@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@9954
@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@9954
@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@9954
@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@9954
@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@9954
@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@9954
@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@9954
@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@9954
@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@9954
@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@9954
@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@9954
@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@9954
@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@9954
commit: 4c928c0
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
codecov
Bot
commented
Dec 7, 2025
•
edited by sentry
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.84%. Comparing base (0d07172) to head (4c928c0).
⚠️ Report is 1 commits behind head on main.
Additional details and impacted files

@@ Coverage Diff @@
## main #9954 +/- ##
===========================================
+ Coverage 45.83% 59.84% +14.01%
===========================================
Files 200 129 -71
Lines 8524 5748 -2776
Branches 1978 1590 -388
===========================================
- Hits 3907 3440 -467
+ Misses 4157 1993 -2164
+ Partials 460 315 -145
🚀 New features to boost your workflow:
- ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
- 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
|
🎉 This PR has been released!
Thank you for your contribution!
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Reviewers
TkDodo
TkDodo approved these changes
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|