Skip to content
Source
Sign inSign up
TanStack/query

fix(query-core): update initialData when an observer mounts while a Query without data exists #9620

MergedTkDodomerged 1 commit intomain fromrefs/pull/9620/headmerged by TkDodo View on GitHub

Showing 2 changed files with 74 additions and 0 deletions.

x
0 of 2 viewed, 2 left
62 additions and 0 deletionspackages/query-core/src/__tests__/query.test.tsxModified
View file
@@ -1193,6 +1193,68 @@
expect(query.state.data).toBe('initial data')
+ test('should update initialData when Query exists without data', async () => {
+ const key = queryKey()
+ const queryFn = vi.fn(async () => {
+ await sleep(100)
+ return 'data'
+ })
+​
+ const promise = queryClient.prefetchQuery({
+ queryKey: key,
+ queryFn,
+ staleTime: 1000,
+ })
+​
+ vi.advanceTimersByTime(50)
+​
+ expect(queryClient.getQueryState(key)).toMatchObject({
+ data: undefined,
+ status: 'pending',
+ fetchStatus: 'fetching',
+ })
+​
+ const observer = new QueryObserver(queryClient, {