Skip to content
Source
Sign inSign up
TanStack/query

fix(core): do not rely on dataUpdatedAt truthiness #7008

MergedTkDodomerged 4 commits intomain fromrefs/pull/7008/headmerged by TkDodo View on GitHub

Showing 4 changed files with 28 additions and 9 deletions (loading 1).

x
0 of 4 viewed, 4 left
18 additions and 0 deletionspackages/query-core/src/tests/query.test.tsxModified
View file
@@ -841,6 +841,24 @@
expect(initialDataUpdatedAtSpy).toHaveBeenCalled()
​
+ test('should work with initialDataUpdatedAt set to zero', async () => {
+ const key = queryKey()
+​
+ await queryClient.prefetchQuery({
+ queryKey: key,
+ queryFn: () => 'data',
+ staleTime: Infinity,
+ initialData: 'initial',
+ initialDataUpdatedAt: 0,
+ })
+​
+ expect(queryCache.find({ queryKey: key })?.state).toMatchObject({
+ data: 'initial',
+ status: 'success',
+ dataUpdatedAt: 0,
+ })
+ })
+​
test('queries should be garbage collected even if they never fetched', async () => {
const key = queryKey()
​