Skip to content
Source
Sign inSign up
TanStack/query

fix(query-core): ensure combine re-executes after cache restoration with memoized combine #9592

Mergedjoseph0926(GitHub profile, opens in a new tab)merged 13 commits intomain fromrefs/pull/9592/headmerged by TkDodo View on GitHub

Showing 4 changed files with 158 additions and 20 deletions (loading 1).

x
0 of 4 viewed, 4 left
47 additions and 0 deletionspackages/query-core/src/__tests__/queriesObserver.test.tsxModified
View file
@@ -347,4 +347,51 @@
expect(queryFn1).toHaveBeenCalledTimes(1)
expect(queryFn2).toHaveBeenCalledTimes(1)
+​
+ test('should notify when results change during early return', async () => {
+ const key1 = queryKey()
+ const key2 = queryKey()
+ const queryFn1 = vi.fn().mockReturnValue(1)
+ const queryFn2 = vi.fn().mockReturnValue(2)
+​
+ queryClient.setQueryData(key1, 1)
+ queryClient.setQueryData(key2, 2)
+​
+ const observer = new QueriesObserver(queryClient, [
+ { queryKey: key1, queryFn: queryFn1 },
+ { queryKey: key2, queryFn: queryFn2 },
+ ])
+​
+ const results: Array<Array<QueryObserverResult>> = []
+ results.push(observer.getCurrentResult())
+​
+ const onUpdate = vi.fn((result: Array<QueryObserverResult>) => {
+ results.push(result)
+ })
+ const unsubscribe = observer.subscribe(onUpdate)