fix(broadcast-client): don't overwrite an existing query's data on an incoming 'added' message #11392
main fromrefs/pull/11392/head·merged by TkDodo View on GitHub🎯 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
addedupdate for the same query. - Allowed queries without data to adopt the broadcasted successful state.
- Continued creating unknown queries from incoming broadcast updates.
- Preserved existing query data when another browser tab broadcasts an
Tests
- Added coverage for cross-tab query synchronization, including populated and data-less queries.
- 1
TkDodo approved these changes
View your CI Pipeline Execution ↗ for commit 0a73db4c255eb44e1889696f8d5a9ddf57934229
Command Status Duration Result nx affected --targets=test:sherif,test:knip,tes...✅ Succeeded 3m 31s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 51s View ↗
☁️ Nx Cloud last updated this comment at
2026-09-21 08:49:50UTCMore templates
- @tanstack/query-example-angular-auto-refetching
- @tanstack/query-example-angular-basic
- @tanstack/query-example-angular-basic-persister
- @tanstack/query-example-angular-devtools-panel
- @tanstack/query-example-angular-infinite-query-with-max-pages
- @tanstack/query-example-angular-optimistic-updates
- @tanstack/query-example-angular-pagination
- @tanstack/query-example-angular-query-options-from-a-service
- @tanstack/query-example-angular-router
- @tanstack/query-example-angular-rxjs
- @tanstack/query-example-angular-simple
- @tanstack/query-example-lit-basic
- @tanstack/query-example-lit-pagination
- @tanstack/query-example-lit-ssr
- @tanstack/query-example-preact-simple
- @tanstack/query-example-solid-astro
- @tanstack/query-example-solid-basic
- @tanstack/query-example-solid-basic-graphql-request
- @tanstack/query-example-solid-default-query-function
- @tanstack/query-example-solid-offline
- @tanstack/query-example-solid-simple
- @tanstack/query-example-solid-start-streaming
- @tanstack/query-example-svelte-auto-refetching
- @tanstack/query-example-svelte-basic
- @tanstack/query-example-svelte-load-more-infinite-scroll
- @tanstack/query-example-svelte-optimistic-updates
- @tanstack/query-example-svelte-playground
- @tanstack/query-example-svelte-simple
- @tanstack/query-example-svelte-ssr
- @tanstack/query-example-svelte-star-wars
- @tanstack/query-example-react-algolia
- @tanstack/query-example-react-auto-refetching
- @tanstack/query-example-react-basic
- @tanstack/query-example-react-basic-graphql-request
- @tanstack/query-example-react-batching
- @tanstack/query-example-chat
- @tanstack/query-example-react-default-query-function
- @tanstack/query-example-react-devtools-panel
- @tanstack/query-example-eslint-legacy
- @tanstack/query-example-eslint-plugin-demo
- @tanstack/query-example-react-infinite-query-with-max-pages
- @tanstack/query-example-react-load-more-infinite-scroll
- @tanstack/query-example-react-nextjs
- @tanstack/query-example-react-nextjs-app-optimistic-updates
- @tanstack/query-example-react-nextjs-app-prefetching
- @tanstack/query-example-nextjs-suspense-streaming
- @tanstack/query-example-react-offline
- @tanstack/query-example-react-pagination
- @tanstack/query-example-react-playground
- @tanstack/query-example-react-prefetching
- @tanstack/query-example-react-react-native
- @tanstack/query-example-react-router
- @tanstack/query-example-react-rick-morty
- @tanstack/query-example-react-shadow-dom
- @tanstack/query-example-react-simple
- @tanstack/query-example-react-star-wars
- @tanstack/query-example-react-suspense
- @tanstack/query-example-vue-2.6-basic
- @tanstack/query-example-vue-2.7-basic
- @tanstack/query-example-vue-basic
- @tanstack/query-example-vue-dependent-queries
- @tanstack/query-example-vue-nuxt3
- @tanstack/query-example-vue-persister
- @tanstack/query-example-vue-simple
@tanstack/angular-query-experimental
npm i https://pkg.pr.new/@tanstack/angular-query-experimental@11392@tanstack/eslint-plugin-query
npm i https://pkg.pr.new/@tanstack/eslint-plugin-query@11392@tanstack/lit-query
npm i https://pkg.pr.new/@tanstack/lit-query@11392@tanstack/preact-query
npm i https://pkg.pr.new/@tanstack/preact-query@11392@tanstack/preact-query-devtools
npm i https://pkg.pr.new/@tanstack/preact-query-devtools@11392@tanstack/preact-query-persist-client
npm i https://pkg.pr.new/@tanstack/preact-query-persist-client@11392@tanstack/query-async-storage-persister
npm i https://pkg.pr.new/@tanstack/query-async-storage-persister@11392@tanstack/query-broadcast-client-experimental
npm i https://pkg.pr.new/@tanstack/query-broadcast-client-experimental@11392@tanstack/query-core
npm i https://pkg.pr.new/@tanstack/query-core@11392@tanstack/query-devtools
npm i https://pkg.pr.new/@tanstack/query-devtools@11392@tanstack/query-persist-client-core
npm i https://pkg.pr.new/@tanstack/query-persist-client-core@11392@tanstack/query-sync-storage-persister
npm i https://pkg.pr.new/@tanstack/query-sync-storage-persister@11392@tanstack/react-query
npm i https://pkg.pr.new/@tanstack/react-query@11392@tanstack/react-query-devtools
npm i https://pkg.pr.new/@tanstack/react-query-devtools@11392@tanstack/react-query-next-experimental
npm i https://pkg.pr.new/@tanstack/react-query-next-experimental@11392@tanstack/react-query-persist-client
npm i https://pkg.pr.new/@tanstack/react-query-persist-client@11392@tanstack/solid-query
npm i https://pkg.pr.new/@tanstack/solid-query@11392@tanstack/solid-query-devtools
npm i https://pkg.pr.new/@tanstack/solid-query-devtools@11392@tanstack/solid-query-persist-client
npm i https://pkg.pr.new/@tanstack/solid-query-persist-client@11392@tanstack/svelte-query
npm i https://pkg.pr.new/@tanstack/svelte-query@11392@tanstack/svelte-query-devtools
npm i https://pkg.pr.new/@tanstack/svelte-query-devtools@11392@tanstack/svelte-query-persist-client
npm i https://pkg.pr.new/@tanstack/svelte-query-persist-client@11392@tanstack/vue-query
npm i https://pkg.pr.new/@tanstack/vue-query@11392@tanstack/vue-query-devtools
npm i https://pkg.pr.new/@tanstack/vue-query-devtools@11392commit:
0a73db4TkDodo merged this3221525
TkDodo closed this
Sign in to join this conversation.
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 d47e3e9df848402bb68f14bba7a5dfb46e6b821f and 0a73db4c255eb44e1889696f8d5a9ddf57934229.
📒 Files selected for processing (1)
packages/query-broadcast-client-experimental/src/__tests__/index.test.ts💤 Files with no reviewable changes (1)
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
addedevent. 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
packages/query-broadcast-client-experimental/src/index.tsundefined.packages/query-broadcast-client-experimental/src/__tests__/index.test.ts,.changeset/fix-broadcast-added-overwrites-existing-data.mdEstimated code review effort: 2 (Simple) | ~10 minutes
Merge Risk: ⚪ Minimal · up to
0a73dThe 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)#
✅ Passed checks (4 passed)
#11391. Existing resolved queries preserve their data, queries without local data adopt incoming state, and the shared handling path applies to browser and s…✨ Finishing Touches
🧪 Generate unit tests (beta)
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