Skip to content

Conversation

@minseong0324
Copy link
Contributor

@minseong0324 minseong0324 commented Dec 7, 2025

🎯 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

  • Fixed an issue where combined query results failed to update when the number of queries changed dynamically. The stable combine reference now properly responds to changes in query composition, ensuring accurate aggregated results when queries are added, removed, or replaced at runtime.

✏️ Tip: You can customize this high-level summary in your review settings.

@changeset-bot
Copy link

changeset-bot bot commented Dec 7, 2025

🦋 Changeset detected

Latest commit: 89db791

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 7, 2025

Walkthrough

This PR fixes a bug where a stable combine reference in QueriesObserver was not being re-invoked when the underlying queries changed dynamically. The fix adds query hash tracking to detect query changes and triggers combine re-evaluation accordingly.

Changes

Cohort / File(s) Summary
Changeset
.changeset/swift-brooms-teach.md
Patch version bump for @tanstack/query-core with description of fix for stable combine reference updating.
Query Core Tests
packages/query-core/src/__tests__/queriesObserver.test.tsx
Adds comprehensive test cases for QueriesObserver covering stable combine behavior with dynamic queries: adding/removing/replacing queries, handling duplicate keys, and verifying combine re-invocation and result updates.
Query Core Implementation
packages/query-core/src/queriesObserver.ts
Adds private field #lastQueryHashes to track query hashes; extends #combineResult to accept and compare query hashes; updates getOptimisticResult to compute and pass query hashes; triggers combine re-evaluation when query hashes change.
React Query Tests
packages/react-query/src/__tests__/useQueries.test.tsx
Adds test case verifying useQueries returns correct results when query count changes with a stable combine reference.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

  • Focus areas:
    • Query hash computation and comparison logic in #combineResult to ensure correct change detection
    • Timing of #lastQueryHashes updates relative to #lastCombine and #lastResult assignments
    • Verify that combine is invoked only when necessary (hash changes) and with correct aggregated results

Possibly related PRs

Suggested labels

package: query-core, package: react-query

Suggested reviewers

  • TkDodo

Poem

🐰 A stable combine, once stuck in time,
Now dances with hashes in perfect rhyme,
When queries shift left, or swap their place,
The combined results show their true face!
Hash-tracking magic, so swift and clean—
Best observer fix the TanStack's seen! 🥬✨

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 PR title accurately describes the main fix: addressing the issue where a stable combine reference wasn't updating correctly when queries changed dynamically.
Linked Issues check ✅ Passed The PR implementation fully addresses issue #8781 by tracking queryHashes in QueriesObserver to detect query changes before result updates, fixing the lag when using stable combine references.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the combine function lag issue: tracking queryHashes, updating combineResult signature, modifying getOptimisticResult, and adding comprehensive test coverage.
Description check ✅ Passed Pull request description includes all required sections: detailed problem statement, solution explanation, completed checklist items, and release impact confirmation with changeset.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

@nx-cloud
Copy link

nx-cloud bot commented Dec 7, 2025

View your CI Pipeline Execution ↗ for commit 89db791

Command Status Duration Result
nx affected --targets=test:sherif,test:knip,tes... ✅ Succeeded 5m 26s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 24s View ↗

☁️ Nx Cloud last updated this comment at 2025-12-07 18:34:00 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 7, 2025

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: 89db791

@codecov
Copy link

codecov bot commented Dec 7, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 60.14%. Comparing base (f15b7fc) to head (89db791).

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##             main    #9954       +/-   ##
===========================================
+ Coverage   45.89%   60.14%   +14.25%     
===========================================
  Files         200      129       -71     
  Lines        8437     5661     -2776     
  Branches     1943     1555      -388     
===========================================
- Hits         3872     3405      -467     
+ Misses       4116     1952     -2164     
+ Partials      449      304      -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.90% <100.00%> (+0.51%) ⬆️
@tanstack/query-devtools 3.48% <ø> (ø)
@tanstack/query-persist-client-core 80.00% <ø> (ø)
@tanstack/query-sync-storage-persister 84.61% <ø> (ø)
@tanstack/query-test-utils ∅ <ø> (∅)
@tanstack/react-query 96.01% <ø> (ø)
@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

combine stable reference is not called with correct parameters

1 participant