Skip to content

fix(query-core): refresh combined result after query-list notifications 🤖🤖🤖 - #12646

Closed
pei711 wants to merge 1 commit into
TanStack:mainfrom
pei711:fix/usequeries-stable-combine-12626
Closed

pei711 wants to merge 1 commit into
TanStack:mainfrom
pei711:fix/usequeries-stable-combine-12626

Conversation

@pei711

@pei711 pei711 commented Nov 20, 2026 •

Copy link
Copy Markdown

Fixes #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:pr completed 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.

@changeset-bot

changeset-bot Bot commented Nov 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: cf61ab6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 26 packages
Name Type
@tanstack/query-core Patch
@tanstack/angular-query Patch
@tanstack/lit-query Patch
@tanstack/preact-query Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-broadcast-client-experimental Patch
@tanstack/query-devtools 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-devtools Patch
@tanstack/angular-query-persist-client Patch
@tanstack/preact-query-devtools Patch
@tanstack/preact-query-persist-client Patch
@tanstack/react-query-devtools Patch
@tanstack/solid-query-devtools Patch
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch
@tanstack/react-query-persist-client Patch
@tanstack/solid-query-persist-client Patch
@tanstack/svelte-query-persist-client Patch
@tanstack/react-query-next-experimental Patch
@tanstack/eslint-plugin-query 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

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
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 cf61ab6 PR 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.

@coderabbitai

coderabbitai Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The notification path now passes current query hashes to combined-result memoization when a combine function 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
#notify passes the current matched query hashes to #combineResult when combine is configured. The regression test checks that a five-query optimistic result remains length five after setQueries receives 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 #combineResult to 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 #notify to keep the cached hashes in sync.

Suggested reviewers: sukvvon, tkdodo

Merge Risk: Minimal · up to cf61a

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed Issue #12626 requires that a stable combine in useQueries returns a result that matches the current query list, even when an existing query updates before setQueries runs. At the reviewed head, …
Out of Scope Changes check Passed 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 #12626 requires that a stable combine in useQueries returns a result that matches the current query list, even when an existing query updates before setQueries runs. At the reviewed head, QueriesObserver.#notify (packages/query-core/src/queriesObserver.ts) now passes this.#observerMatches.map(match => match.defaultedQueryOptions.queryHash) to #combineResult when combine is configured. This is the remediation the issue proposes. In the reported sequence, the notification from query list A sets #lastQueryHashes to A. The next render with list B then sees queryHashesChanged === 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. The pnpm run test:pr workspace 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.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 8b2e8af and cf61ab6.

Files selected for processing: 3

  • .changeset/soft-bears-race.md
  • packages/query-core/src/__tests__/queriesObserver.test.tsx
  • packages/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 TkDodo closed this Nov 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

useQueries: stable combine returns a stale result when a query updates before setQueries runs

2 participants