Skip to content
Source
Sign inSign up
TanStack/query

preserve error state on added message #12563

Openracheltcp(GitHub profile, opens in a new tab)wants to merge 1 commit intomain fromrefs/pull/12563/headopened View on GitHub

Showing 3 changed files with 29 additions and 1 deletion.

x
0 of 3 viewed, 3 left
5 additions and 0 deletions.changeset/tangy-trees-swim.mdAdded
View file
@@ -0,0 +1,5 @@
+---
+"@tanstack/query-broadcast-client-experimental": patch
+---
+​
+Prevent incoming added messages from overwriting existing query error states
23 additions and 0 deletionspackages/query-broadcast-client-experimental/src/__tests__/index.test.tsModified
View file
@@ -164,6 +164,29 @@
expect(queryClient.getQueryState(existingKey)?.status).toBe('success')
​
+ it('should preserve an error when an added message has no data', () => {
+ const key = createKey()
+ const err = new Error('request failed')
+​
+ broadcastQueryClient({
+ queryClient,
+ broadcastChannel: 'test_channel',
+ })
+​
+ const q = queryCache.build(queryClient, { queryKey: key })
+ q.setState({ status: 'error', error: err, fetchStatus: 'idle' })
+​
+ lastCreatedChannel.onmessage?.({
+ type: 'added',
+ queryHash: q.queryHash,
+ queryKey: key,
+ state: { status: 'pending', data: undefined, error: null },
+ })