Skip to content

fix(broadcast-client): don't overwrite an existing query's data on an incoming 'added' message - #11392

Open
lazerg wants to merge 2 commits into
TanStack:mainfrom
lazerg:fix/issue-11391-broadcast-added-overwrite
Open

fix(broadcast-client): don't overwrite an existing query's data on an incoming 'added' message#11392
lazerg wants to merge 2 commits into
TanStack:mainfrom
lazerg:fix/issue-11391-broadcast-added-overwrite

Conversation

@lazerg

@lazerg lazerg commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

🎯 Changes

Since 5.102.0, the added broadcast message carries the query's state, and the receiving tab applies it with query.setState(state) whenever the query already exists locally. A tab mounting a query for the first time always broadcasts added, even if it hasn't fetched yet, so any other tab that already has resolved data for that key gets reset back to pending with no data.

This only skips setState when the local query already has data, so a query that has never resolved locally can still adopt state from an added message (matches how a brand-new tab picks up a key another tab already resolved via initialData), while an already-resolved query in one tab won't get clobbered just because another tab mounts the same key.

Fixes #11391

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally.
  • I 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.

Summary by CodeRabbit

  • Bug Fixes

    • Preserved existing query data when another browser tab broadcasts an added update for the same query.
    • Allowed queries without data to adopt the broadcasted successful state.
    • Continued creating unknown queries from incoming broadcast updates.
  • Tests

    • Added coverage for cross-tab query synchronization, including populated and data-less queries.

@coderabbitai

coderabbitai Bot commented Sep 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Team

Run ID: 39f92968-21f7-468f-a281-699e5b272555

📥 Commits

Reviewing files that changed from the base of the PR and between d47e3e9 and 0a73db4.

📒 Files selected for processing (1)
  • packages/query-broadcast-client-experimental/src/__tests__/index.test.ts
💤 Files with no reviewable changes (1)
  • packages/query-broadcast-client-experimental/src/tests/index.test.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

The broadcast client now preserves existing query data when it receives an added event. It applies the broadcast state only to existing queries without data and builds unknown queries from the broadcast state. Tests cover both existing-query cases, and a patch changeset documents the fix.

Changes

Broadcast added-state handling

Layer / File(s) Summary
Conditional handling for added broadcasts
packages/query-broadcast-client-experimental/src/index.ts
Existing queries receive the broadcast state only when their current data is undefined.
Added-state regression coverage and release metadata
packages/query-broadcast-client-experimental/src/__tests__/index.test.ts, .changeset/fix-broadcast-added-overwrites-existing-data.md
Tests cover resolved and data-less queries. The changeset declares a patch release.

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

Merge Risk: ⚪ Minimal · up to 0a73d

The broadcast client preserves resolved local query data when receiving an added message while allowing data-less queries to adopt incoming state. No merge-blocking risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ 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%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary fix: preventing incoming 'added' messages from overwriting existing query data.
Description check ✅ Passed The description covers the change, motivation, linked issue, testing, contributor checklist, and changeset requirement. It is complete enough for review.
Linked Issues check ✅ Passed The implementation and tests satisfy issue #11391. Existing resolved queries preserve their data, queries without local data adopt incoming state, and the shared handling path applies to browser and s…
Out of Scope Changes check ✅ Passed The changeset, implementation change, and focused tests are directly related to fixing the incoming 'added' message behavior. No unrelated changes are present.
  • Fix all pre-merge checks with AI
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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.

[query-broadcast-client-experimental] Since 5.102.0 a newly mounted query overwrites the same query's resolved data in every other tab

1 participant