Skip to content

Commit 5221029

Browse files
sukvvonmanudeli
andauthored
test(react-query/HydrationBoundary): add tests for 'non-object' state and missing 'queries' property handling (#9605)
Co-authored-by: Jonghyeon Ko <[email protected]>
1 parent aec19c9 commit 5221029

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

packages/react-query/src/__tests__/HydrationBoundary.test.tsx

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -362,6 +362,54 @@ describe('React hydration', () => {
362362
queryClient.clear()
363363
})
364364

365+
test('should not hydrate queries if state is not an object', async () => {
366+
const queryClient = new QueryClient()
367+
368+
const hydrateSpy = vi.spyOn(coreModule, 'hydrate')
369+
370+
function Page() {
371+
return null
372+
}
373+
374+
render(
375+
<QueryClientProvider client={queryClient}>
376+
<HydrationBoundary state={'invalid-state' as any}>
377+
<Page />
378+
</HydrationBoundary>
379+
</QueryClientProvider>,
380+
)
381+
382+
await vi.advanceTimersByTimeAsync(0)
383+
expect(hydrateSpy).toHaveBeenCalledTimes(0)
384+
385+
hydrateSpy.mockRestore()
386+
queryClient.clear()
387+
})
388+
389+
test('should handle state without queries property gracefully', async () => {
390+
const queryClient = new QueryClient()
391+
392+
const hydrateSpy = vi.spyOn(coreModule, 'hydrate')
393+
394+
function Page() {
395+
return null
396+
}
397+
398+
render(
399+
<QueryClientProvider client={queryClient}>
400+
<HydrationBoundary state={{} as any}>
401+
<Page />
402+
</HydrationBoundary>
403+
</QueryClientProvider>,
404+
)
405+
406+
await vi.advanceTimersByTimeAsync(0)
407+
expect(hydrateSpy).toHaveBeenCalledTimes(0)
408+
409+
hydrateSpy.mockRestore()
410+
queryClient.clear()
411+
})
412+
365413
// https://github.com/TanStack/query/issues/8677
366414
test('should not infinite loop when hydrating promises that resolve to errors', async () => {
367415
const originalHydrate = coreModule.hydrate

0 commit comments

Comments
 (0)