Skip to content
Source
Sign inSign up
TanStack/query

fix(broadcast-client): don't overwrite a query in error with an incoming 'added' message that has no data #12215

Openlazerg(GitHub profile, opens in a new tab)wants to merge 3 commits intomain fromrefs/pull/12215/headopened View on GitHub

Showing 3 changed files with 71 additions and 1 deletion.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/broadcast-added-keeps-error.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+'@tanstack/query-broadcast-client-experimental': patch
+---
+​
+fix: don't overwrite a query that has no data, such as one in error, when another tab broadcasts an `added` event for a query that has not settled yet
65 additions and 0 deletionspackages/query-broadcast-client-experimental/src/__tests__/index.test.tsModified
View file
@@ -175,6 +175,71 @@
value: 'from other tab',
+​
+ it('should not overwrite an existing query in error when an "added" message with a fresh state arrives for it', async () => {
+ const existingKey = queryKey()
+ const error = new Error('down')
+​
+ broadcastQueryClient({
+ queryClient,
+ broadcastChannel: 'test_channel',
+ })
+​
+ await queryClient
+ .query({
+ queryKey: existingKey,
+ queryFn: () => Promise.reject(error),
+ retry: false,
+ })
+ .catch(() => undefined)
+ const existingQuery = queryCache.find({ queryKey: existingKey })!