Skip to content
Source
Sign inSign up
TanStack/query

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

Opendraarivpatel-ui(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/12704/headopened View on GitHub

Showing 3 changed files with 48 additions and 1 deletion.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/broadcast-added-error-state.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/query-broadcast-client-experimental': patch
+---
+​
+fix(query-broadcast-client-experimental): do not overwrite an error-settled query that has no data when an `added` broadcast arrives
35 additions and 0 deletionspackages/query-broadcast-client-experimental/src/__tests__/index.test.tsModified
View file
@@ -164,6 +164,41 @@
expect(queryClient.getQueryState(existingKey)?.status).toBe('success')
​
+ it('should not overwrite an error-settled query that has no data when an "added" message arrives', () => {
+ const existingKey = createKey()
+​
+ broadcastQueryClient({
+ queryClient,
+ broadcastChannel: 'test_channel',
+ })
+​
+ // This tab's query already settled in error, so it has no data but
+ // did fail: overwriting it with the sender's brand-new state would
+ // drop the error and make it look pending without a fetch running.
+ const existingQuery = queryCache.build(queryClient, {
+ queryKey: existingKey,
+ })
+ existingQuery.setState({
+ status: 'error',
+ error: new Error('boom'),
+ errorUpdatedAt: 1,