@@ -54,9 +54,9 @@ describe('React hydration', () => {
54
54
</ HydrationBoundary >
55
55
</ QueryClientProvider > ,
56
56
)
57
- await vi . advanceTimersByTimeAsync ( 1 )
57
+
58
58
expect ( rendered . getByText ( 'stringCached' ) ) . toBeInTheDocument ( )
59
- await vi . advanceTimersByTimeAsync ( 20 )
59
+ await vi . advanceTimersByTimeAsync ( 21 )
60
60
expect ( rendered . getByText ( 'string' ) ) . toBeInTheDocument ( )
61
61
queryClient . clear ( )
62
62
} )
@@ -89,9 +89,8 @@ describe('React hydration', () => {
89
89
</ QueryClientProvider > ,
90
90
)
91
91
92
- await vi . advanceTimersByTimeAsync ( 1 )
93
92
expect ( rendered . getByText ( 'stringCached' ) ) . toBeInTheDocument ( )
94
- await vi . advanceTimersByTimeAsync ( 20 )
93
+ await vi . advanceTimersByTimeAsync ( 21 )
95
94
expect ( rendered . getByText ( 'string' ) ) . toBeInTheDocument ( )
96
95
97
96
queryClientInner . clear ( )
@@ -123,9 +122,8 @@ describe('React hydration', () => {
123
122
</ QueryClientProvider > ,
124
123
)
125
124
126
- await vi . advanceTimersByTimeAsync ( 1 )
127
125
expect ( rendered . getByText ( 'stringCached' ) ) . toBeInTheDocument ( )
128
- await vi . advanceTimersByTimeAsync ( 20 )
126
+ await vi . advanceTimersByTimeAsync ( 21 )
129
127
expect ( rendered . getByText ( 'string' ) ) . toBeInTheDocument ( )
130
128
131
129
const intermediateClient = new QueryClient ( )
@@ -134,7 +132,6 @@ describe('React hydration', () => {
134
132
queryKey : [ 'string' ] ,
135
133
queryFn : ( ) => sleep ( 20 ) . then ( ( ) => [ 'should change' ] ) ,
136
134
} )
137
- await vi . advanceTimersByTimeAsync ( 20 )
138
135
intermediateClient . prefetchQuery ( {
139
136
queryKey : [ 'added' ] ,
140
137
queryFn : ( ) => sleep ( 20 ) . then ( ( ) => [ 'added' ] ) ,
@@ -158,9 +155,9 @@ describe('React hydration', () => {
158
155
// New query data should be available immediately
159
156
expect ( rendered . getByText ( 'added' ) ) . toBeInTheDocument ( )
160
157
161
- await vi . advanceTimersByTimeAsync ( 20 )
158
+ await vi . advanceTimersByTimeAsync ( 0 )
162
159
// After effects phase has had time to run, the observer should have updated
163
- expect ( rendered . queryByText ( 'string' ) ) . toBeNull ( )
160
+ expect ( rendered . queryByText ( 'string' ) ) . not . toBeInTheDocument ( )
164
161
expect ( rendered . getByText ( 'should change' ) ) . toBeInTheDocument ( )
165
162
166
163
queryClient . clear ( )
@@ -196,17 +193,15 @@ describe('React hydration', () => {
196
193
</ QueryClientProvider > ,
197
194
)
198
195
199
- await vi . advanceTimersByTimeAsync ( 1 )
200
196
expect ( rendered . getByText ( 'stringCached' ) ) . toBeInTheDocument ( )
201
- await vi . advanceTimersByTimeAsync ( 20 )
197
+ await vi . advanceTimersByTimeAsync ( 21 )
202
198
expect ( rendered . getByText ( 'string' ) ) . toBeInTheDocument ( )
203
199
204
200
const intermediateClient = new QueryClient ( )
205
201
intermediateClient . prefetchQuery ( {
206
202
queryKey : [ 'string' ] ,
207
203
queryFn : ( ) => sleep ( 20 ) . then ( ( ) => [ 'should not change' ] ) ,
208
204
} )
209
- await vi . advanceTimersByTimeAsync ( 20 )
210
205
intermediateClient . prefetchQuery ( {
211
206
queryKey : [ 'added' ] ,
212
207
queryFn : ( ) => sleep ( 20 ) . then ( ( ) => [ 'added' ] ) ,
@@ -238,7 +233,7 @@ describe('React hydration', () => {
238
233
</ React . Suspense > ,
239
234
)
240
235
241
- rendered . getByText ( 'loading' )
236
+ expect ( rendered . getByText ( 'loading' ) ) . toBeInTheDocument ( )
242
237
} )
243
238
244
239
React . startTransition ( ( ) => {
@@ -253,7 +248,9 @@ describe('React hydration', () => {
253
248
254
249
// This query existed before the transition so it should stay the same
255
250
expect ( rendered . getByText ( 'string' ) ) . toBeInTheDocument ( )
256
- expect ( rendered . queryByText ( 'should not change' ) ) . toBeNull ( )
251
+ expect (
252
+ rendered . queryByText ( 'should not change' ) ,
253
+ ) . not . toBeInTheDocument ( )
257
254
// New query data should be available immediately because it was
258
255
// hydrated in the previous transition, even though the new dehydrated
259
256
// state did not contain it
@@ -263,7 +260,7 @@ describe('React hydration', () => {
263
260
await vi . advanceTimersByTimeAsync ( 20 )
264
261
// It should stay the same even after effects have had a chance to run
265
262
expect ( rendered . getByText ( 'string' ) ) . toBeInTheDocument ( )
266
- expect ( rendered . queryByText ( 'should not change' ) ) . toBeNull ( )
263
+ expect ( rendered . queryByText ( 'should not change' ) ) . not . toBeInTheDocument ( )
267
264
268
265
queryClient . clear ( )
269
266
} )
@@ -292,9 +289,8 @@ describe('React hydration', () => {
292
289
</ QueryClientProvider > ,
293
290
)
294
291
295
- await vi . advanceTimersByTimeAsync ( 1 )
296
292
expect ( rendered . getByText ( 'stringCached' ) ) . toBeInTheDocument ( )
297
- await vi . advanceTimersByTimeAsync ( 20 )
293
+ await vi . advanceTimersByTimeAsync ( 21 )
298
294
expect ( rendered . getByText ( 'string' ) ) . toBeInTheDocument ( )
299
295
const newClientQueryClient = new QueryClient ( )
300
296
@@ -359,7 +355,7 @@ describe('React hydration', () => {
359
355
</ QueryClientProvider > ,
360
356
)
361
357
362
- await vi . runAllTimersAsync ( )
358
+ await vi . advanceTimersByTimeAsync ( 0 )
363
359
expect ( hydrateSpy ) . toHaveBeenCalledTimes ( 0 )
364
360
365
361
hydrateSpy . mockRestore ( )
@@ -386,12 +382,11 @@ describe('React hydration', () => {
386
382
// For the bug to trigger, there needs to already be a query in the cache,
387
383
// with a dataUpdatedAt earlier than the dehydratedAt of the next query
388
384
const clientQueryClient = new QueryClient ( )
389
- await clientQueryClient . prefetchQuery ( {
385
+ clientQueryClient . prefetchQuery ( {
390
386
queryKey : [ 'promise' ] ,
391
- queryFn : ( ) => 'existing' ,
387
+ queryFn : ( ) => sleep ( 20 ) . then ( ( ) => 'existing' ) ,
392
388
} )
393
-
394
- await vi . advanceTimersByTimeAsync ( 100 )
389
+ await vi . advanceTimersByTimeAsync ( 20 )
395
390
396
391
const prefetchQueryClient = new QueryClient ( {
397
392
defaultOptions : {
@@ -402,10 +397,8 @@ describe('React hydration', () => {
402
397
} )
403
398
prefetchQueryClient . prefetchQuery ( {
404
399
queryKey : [ 'promise' ] ,
405
- queryFn : async ( ) => {
406
- await sleep ( 10 )
407
- throw new Error ( 'Query failed' )
408
- } ,
400
+ queryFn : ( ) =>
401
+ sleep ( 10 ) . then ( ( ) => Promise . reject ( new Error ( 'Query failed' ) ) ) ,
409
402
} )
410
403
411
404
const dehydratedState = dehydrate ( prefetchQueryClient )
@@ -422,7 +415,7 @@ describe('React hydration', () => {
422
415
function Page ( ) {
423
416
const { data } = useQuery ( {
424
417
queryKey : [ 'promise' ] ,
425
- queryFn : ( ) => sleep ( 10 ) . then ( ( ) => [ 'new' ] ) ,
418
+ queryFn : ( ) => sleep ( 20 ) . then ( ( ) => [ 'new' ] ) ,
426
419
} )
427
420
return (
428
421
< div >
@@ -438,9 +431,9 @@ describe('React hydration', () => {
438
431
</ HydrationBoundary >
439
432
</ QueryClientProvider > ,
440
433
)
441
- await vi . advanceTimersByTimeAsync ( 1 )
434
+
442
435
expect ( rendered . getByText ( 'existing' ) ) . toBeInTheDocument ( )
443
- await vi . advanceTimersByTimeAsync ( 10 )
436
+ await vi . advanceTimersByTimeAsync ( 21 )
444
437
expect ( rendered . getByText ( 'new' ) ) . toBeInTheDocument ( )
445
438
446
439
process . removeListener ( 'unhandledRejection' , ignore )
0 commit comments