Skip to content

fix(query-broadcast-client-experimental): keep error state of settled queries on added broadcasts - #12704

Open
draarivpatel-ui wants to merge 1 commit into
TanStack:mainfrom
draarivpatel-ui:fix-broadcast-added-error-state
Open

draarivpatel-ui wants to merge 1 commit into
TanStack:mainfrom
draarivpatel-ui:fix-broadcast-added-error-state

Conversation

@draarivpatel-ui

@draarivpatel-ui draarivpatel-ui commented Nov 25, 2026 •

Copy link
Copy Markdown

Changes

When another tab creates a query, the receiving tab applied the sender's initial state on added whenever its own query had no data. A query that already settled in error has no data either, so it was replaced with the sender's brand-new state: status: 'pending', error: null, errorUpdatedAt: 0. The error was lost and observers rendered a pending UI indefinitely without any fetch running, exactly as described in the issue.

added messages carry the sender's initial state at creation time, so adopting them is only ever meaningful for a query that has not settled yet. The receiver now also requires errorUpdatedAt === 0 before adopting, so a query that already failed keeps its error state.

Fixes #12213

Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested code changes locally with the package's vitest suite (the full pnpm run test:pr matrix does not apply to this single-package change and was not run).
  • I have followed the AI contribution policy and fully understand the code in this pull request, including any code generated with AI assistance.

Release impact

  • This change affects published code, and I have generated a changeset (patch on @tanstack/query-broadcast-client-experimental).

Verification

  • New regression test: an error-settled query with no data keeps its error state when an added message with a fresh pending state arrives.
  • The regression test fails on current main (1 failed, 13 passed) and passes with the fix (14 passed, vitest run for @tanstack/query-broadcast-client-experimental).
  • The two pre-existing added-handling tests still pass: queries with data are never overwritten, and unsettled queries with no data still adopt the sender's state.
  • Size limit comparison: pending/unavailable locally; the change is one extra numeric comparison in the broadcast message handler of the experimental broadcast package.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed an issue where an incoming query update could replace an existing error state when the query had no data. The error status and message are now preserved when the local query has already settled with an error, preventing the displayed state from incorrectly changing to pending.

… queries on `added` broadcasts

When another tab creates a query, the receiving tab applied the sender's
initial state whenever its own query had no data. A query that settled
in error has no data either, so it was replaced with the sender's
brand-new pending state: the error was lost and the query looked like it
was loading while no fetch was running.

Only adopt the sender's initial state for queries that have not settled
yet.

Fixes TanStack#12213
Copilot AI balanced review requested due to automatic review settings November 25, 2026 19:25
@changeset-bot

changeset-bot Bot commented Nov 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 56d94f4

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-broadcast-client-experimental Patch
@tanstack/angular-query-devtools Patch
@tanstack/angular-query-persist-client Patch
@tanstack/angular-query Patch
@tanstack/eslint-plugin-query Patch
@tanstack/preact-query-devtools Patch
@tanstack/preact-query-persist-client Patch
@tanstack/preact-query Patch
@tanstack/query-async-storage-persister Patch
@tanstack/query-core Patch
@tanstack/query-devtools Patch
@tanstack/query-persist-client-core Patch
@tanstack/query-sync-storage-persister Patch
@tanstack/react-query-devtools Patch
@tanstack/react-query-next-experimental Patch
@tanstack/react-query-persist-client Patch
@tanstack/react-query Patch
@tanstack/solid-query-devtools Patch
@tanstack/solid-query-persist-client Patch
@tanstack/solid-query Patch
@tanstack/vue-query Patch
@tanstack/lit-query Patch
@tanstack/svelte-query Patch
@tanstack/svelte-query-devtools Patch
@tanstack/vue-query-devtools Patch
@tanstack/svelte-query-persist-client 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

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

When an existing query has no data but has a recorded error, the broadcast client now keeps its local state after receiving an added message. A regression test verifies that the error status and value remain unchanged.

Changes: Added broadcast state handling

Layer / File(s) Summary
Guard added-state adoption
packages/query-broadcast-client-experimental/src/index.ts, packages/query-broadcast-client-experimental/src/__tests__/index.test.ts, .changeset/broadcast-added-error-state.md
The receiver adopts an incoming added state only when its query has no data and errorUpdatedAt is zero. The test checks that a query with an existing error keeps its status and error value. The changeset declares a patch release.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Possibly related PRs

  • TanStack/query#12563: Addresses the same issue by changing how the broadcast client handles incoming added states.

Suggested reviewers: lazerg, sukvvon

Merge Risk: Minimal · up to 56d94

This patch keeps a query's recorded error from being overwritten by an incoming added message that would leave it pending with no fetch running. It is a small, well-tested change in an experimental package, so merge-readiness risk is minimal.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title names the package and the fix: error state of settled queries is kept when an added broadcast arrives. This matches the main change in index.ts and the added test. The title is 97 characters…
Description check Passed The description follows the template. It explains the bug and the fix, and it links issue #12213. It lists the checklist items and the release impact with a changeset. It also adds a verification sect…
Linked Issues check Passed Issue #12213 requires that an added message not overwrite a receiving query that has no data but has settled in error. At head, packages/query-broadcast-client-experimental/src/index.ts changes th…
Out of Scope Changes check Passed The reviewed changes are limited to the added branch guard in src/index.ts (one added condition with a comment), a regression test in src/__tests__/index.test.ts, and a patch changeset for `@tan…
Full details: Title check

Explanation

The title names the package and the fix: error state of settled queries is kept when an added broadcast arrives. This matches the main change in index.ts and the added test. The title is 97 characters, which is long, but it stays specific and on topic.

Full details: Description check

Explanation

The description follows the template. It explains the bug and the fix, and it links issue #12213. It lists the checklist items and the release impact with a changeset. It also adds a verification section with test results. The Changes section states the motivation clearly. The description is mostly complete, so the check passes.

Full details: Linked Issues check

Explanation

Issue #12213 requires that an added message not overwrite a receiving query that has no data but has settled in error. At head, packages/query-broadcast-client-experimental/src/index.ts changes the added branch to call query.setState(state) only when query.state.data === undefined && query.state.errorUpdatedAt === 0. A receiver with a recorded error (errorUpdatedAt > 0) keeps its error state. The issue's suggested fix (apply only when the incoming state has dataUpdatedAt > 0 or errorUpdatedAt > 0) is a different guard. The PR uses the receiver-side guard that the issue describes as the stricter freshness-style option. The sender's added state is always the initial state at build time, so the receiver-side guard covers the reported case. The existing behavior for receivers with data (#11391) is unchanged. The summary and the AI-generated summary report a regression test for the error-settled case and two existing added tests. I did not run or read the test file, so the test evidence rests on the PR description and summary. Remaining added behavior for receivers that are still pending with fetchStatus set is unchanged and is not part of #12213.

Full details: Out of Scope Changes check

Explanation

The reviewed changes are limited to the added branch guard in src/index.ts (one added condition with a comment), a regression test in src/__tests__/index.test.ts, and a patch changeset for @tanstack/query-broadcast-client-experimental. All three directly support the fix for #12213. No public API or unrelated behavior changed according to the diff and summary. I did not inspect the test file or changeset contents directly.

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 18b1ade and 56d94f4.

Files selected for processing: 3

  • .changeset/broadcast-added-error-state.md
  • packages/query-broadcast-client-experimental/src/__tests__/index.test.ts
  • packages/query-broadcast-client-experimental/src/index.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.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

2 participants