GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

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

@minseong0324 minseong0324 commented Dec 7, 2025 •
edited by coderabbitai Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

🎯 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.

All reactions
minseong0324 added 3 commits December 8, 2025 03:23
@minseong0324
test(query-core, react-query): add tests for stable combine reference…
4f794b2
… with dynamic queries
@minseong0324
fix(query-core): fix combine cache invalidation with stable reference
ce349f5
@minseong0324
chore: add changesets
89db791
@changeset-bot

changeset-bot Bot commented Dec 7, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

🦋 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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai

coderabbitai Bot commented Dec 7, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor
📝 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

  • fix(query-core): ensure combine re-executes after cache restoration with memoized combine #9592 — Related changes ensuring memoized combine re-runs when queries or their results change (per-index and overall change-detection overlap).
  • fix(query-core, react-query): infinite re-renders in useQueries #9639 — Related refinements to queriesObserver change-detection and observer reconfiguration to avoid incorrect/infinite updates.
  • fix: Prevent infinite render loops when useSuspenseQueries has duplicate queryKeys #9886 — Additional modifications around queryHash handling and observer matching in QueriesObserver.

Suggested reviewers

  • TkDodo

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
  • 📝 Generate docstrings

📜 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:

  1. First call: #lastQueryHashes is undefined → queryHashesChanged is false, but #combinedResult is also undefined, so recomputation happens anyway.
  2. Subsequent optimistic calls: Both hash arrays are defined, enabling detection of query additions/removals/replacements.
  3. #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:

  1. By the time #notify() executes, setQueries has already updated this.#result
  2. 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
  • X
  • Mastodon
  • Reddit
  • LinkedIn

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added package: react-query package: query-core labels Dec 7, 2025
@nx-cloud

nx-cloud Bot commented Dec 7, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@pkg-pr-new

pkg-pr-new Bot commented Dec 7, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
More templates

  • @tanstack/query-example-angular-auto-refetching
  • @tanstack/query-example-angular-basic
  • @tanstack/query-example-angular-basic-persister
  • @tanstack/query-example-angular-devtools-panel
  • @tanstack/query-example-angular-infinite-query-with-max-pages
  • @tanstack/query-example-angular-optimistic-updates
  • @tanstack/query-example-angular-pagination
  • @tanstack/query-example-angular-query-options-from-a-service
  • @tanstack/query-example-angular-router
  • @tanstack/query-example-angular-rxjs
  • @tanstack/query-example-angular-simple
  • @tanstack/query-example-solid-astro
  • @tanstack/query-example-solid-basic
  • @tanstack/query-example-solid-basic-graphql-request
  • @tanstack/query-example-solid-default-query-function
  • @tanstack/query-example-solid-simple
  • @tanstack/query-example-solid-start-streaming
  • @tanstack/query-example-vue-2.6-basic
  • @tanstack/query-example-vue-2.7-basic
  • @tanstack/query-example-vue-basic
  • @tanstack/query-example-vue-dependent-queries
  • @tanstack/query-example-vue-nuxt3
  • @tanstack/query-example-vue-persister
  • @tanstack/query-example-vue-simple
  • @tanstack/query-example-svelte-auto-refetching
  • @tanstack/query-example-svelte-basic
  • @tanstack/query-example-svelte-load-more-infinite-scroll
  • @tanstack/query-example-svelte-optimistic-updates
  • @tanstack/query-example-svelte-playground
  • @tanstack/query-example-svelte-simple
  • @tanstack/query-example-svelte-ssr
  • @tanstack/query-example-svelte-star-wars
  • @tanstack/query-example-react-algolia
  • @tanstack/query-example-react-auto-refetching
  • @tanstack/query-example-react-basic
  • @tanstack/query-example-react-basic-graphql-request
  • @tanstack/query-example-chat
  • @tanstack/query-example-react-default-query-function
  • @tanstack/query-example-react-devtools-panel
  • @tanstack/query-example-eslint-legacy
  • @tanstack/query-example-react-infinite-query-with-max-pages
  • @tanstack/query-example-react-load-more-infinite-scroll
  • @tanstack/query-example-react-nextjs
  • @tanstack/query-example-react-nextjs-app-prefetching
  • @tanstack/query-example-nextjs-suspense-streaming
  • @tanstack/query-example-react-offline
  • @tanstack/query-example-react-optimistic-updates-cache
  • @tanstack/query-example-react-optimistic-updates-ui
  • @tanstack/query-example-react-pagination
  • @tanstack/query-example-react-playground
  • @tanstack/query-example-react-prefetching
  • @tanstack/query-example-react-react-native
  • @tanstack/query-example-react-router
  • @tanstack/query-example-react-rick-morty
  • @tanstack/query-example-react-shadow-dom
  • @tanstack/query-example-react-simple
  • @tanstack/query-example-react-star-wars
  • @tanstack/query-example-react-suspense

@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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@codecov

codecov Bot commented Dec 7, 2025 •
edited by sentry Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Codecov Report

✅ 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

Impacted file tree graph

@@             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     
Components Coverage Δ
@tanstack/angular-query-experimental 93.85% <ø> (ø)
@tanstack/eslint-plugin-query ∅ <ø> (∅)
@tanstack/query-async-storage-persister 43.85% <ø> (ø)
@tanstack/query-broadcast-client-experimental 24.39% <ø> (ø)
@tanstack/query-codemods ∅ <ø> (∅)
@tanstack/query-core 97.88% <100.00%> (+0.50%) ⬆️
@tanstack/query-devtools 3.38% <ø> (ø)
@tanstack/query-persist-client-core 80.00% <ø> (ø)
@tanstack/query-sync-storage-persister 84.61% <ø> (ø)
@tanstack/query-test-utils ∅ <ø> (∅)
@tanstack/react-query 96.73% <ø> (ø)
@tanstack/react-query-devtools 9.25% <ø> (ø)
@tanstack/react-query-next-experimental ∅ <ø> (∅)
@tanstack/react-query-persist-client 100.00% <ø> (ø)
@tanstack/solid-query 77.81% <ø> (ø)
@tanstack/solid-query-devtools 64.17% <ø> (ø)
@tanstack/solid-query-persist-client 100.00% <ø> (ø)
@tanstack/svelte-query ∅ <ø> (∅)
@tanstack/svelte-query-devtools ∅ <ø> (∅)
@tanstack/svelte-query-persist-client ∅ <ø> (∅)
@tanstack/vue-query 71.91% <ø> (ø)
@tanstack/vue-query-devtools ∅ <ø> (∅)
🚀 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.
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

minseong0324 and others added 3 commits December 29, 2025 00:00
@minseong0324
Merge branch 'main' into fix/combine-bug
b0b1028
@minseong0324
Merge branch 'main' into fix/combine-bug
291afec
@TkDodo
Merge branch 'main' into fix/combine-bug
4c928c0
TkDodo
TkDodo approved these changes Jan 16, 2026
View reviewed changes
@TkDodo
TkDodo merged commit 53fc74e into TanStack:main Jan 16, 2026
8 of 9 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot mentioned this pull request Jan 16, 2026
ci: Version Packages #10047
Merged
@github-actions

github-actions Bot commented Jan 17, 2026

Copy link
Copy Markdown
Contributor

🎉 This PR has been released!

  • @tanstack/[email protected]

Thank you for your contribution!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@coderabbitai coderabbitai Bot mentioned this pull request Jan 31, 2026
fix(react-query): retry useQuery().promise on error boundary reset #10079
Closed
3 of 4 tasks
@swheel33 swheel33 mentioned this pull request Nov 18, 2026
useQueries: stable combine returns a stale result when a query updates before setQueries runs #12626
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@TkDodo TkDodo TkDodo approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

package: query-core package: react-query

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

combine stable reference is not called with correct parameters

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@minseong0324 @TkDodo
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.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.