Skip to content
Source
Sign inSign up
TanStack/query

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

Closedpei711(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/12646/headopened View on GitHub

pei711(GitHub profile, opens in a new tab)commented

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.
    1. 🦋 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
      NameType
      @tanstack/query-corePatch
      @tanstack/angular-queryPatch
      @tanstack/lit-queryPatch
      @tanstack/preact-queryPatch
      @tanstack/query-async-storage-persisterPatch
      @tanstack/query-broadcast-client-experimentalPatch
      @tanstack/query-devtoolsPatch
      @tanstack/query-persist-client-corePatch
      @tanstack/query-sync-storage-persisterPatch
      @tanstack/react-queryPatch
      @tanstack/solid-queryPatch
      @tanstack/svelte-queryPatch
      @tanstack/vue-queryPatch
      @tanstack/angular-query-devtoolsPatch
      @tanstack/angular-query-persist-clientPatch
      @tanstack/preact-query-devtoolsPatch
      @tanstack/preact-query-persist-clientPatch
      @tanstack/react-query-devtoolsPatch
      @tanstack/solid-query-devtoolsPatch
      @tanstack/svelte-query-devtoolsPatch
      @tanstack/vue-query-devtoolsPatch
      @tanstack/react-query-persist-clientPatch
      @tanstack/solid-query-persist-clientPatch
      @tanstack/svelte-query-persist-clientPatch
      @tanstack/react-query-next-experimentalPatch
      @tanstack/eslint-plugin-queryPatch

      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

    2. chatgpt-codex-connector[bot](GitHub profile, opens in a new tab)commented
      Codex Review Summary: ✅ Completed

      This comment shows the latest Codex review activity on this pull request.

      ReviewStatusCommitReview trigger
      📝 Code Review✅ Completed 2026-11-20T20:45:00.602728Zcf61ab6PR 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.

    3. tanstack-source added labelsbug

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      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 nameStatusExplanation
      Title checkPassedThe 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 checkPassedThe 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 checkPassedIssue #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 checkPassedAll 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 8b2e8af0768c12500e914ac7055f007c65d8316a and cf61ab6c8674ae1c3edc09268e218abff1db528a.

      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.

    5. TkDodo closed this

Sign in to join this conversation.