Skip to content

test(react-query): ensure HydrationBoundary does not hydrate when state is truthy and non-object #8946

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 26 additions & 7 deletions packages/react-query/src/__tests__/HydrationBoundary.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -331,12 +331,8 @@ describe('React hydration', () => {
</QueryClientProvider>,
)

await Promise.all(
Array.from({ length: 1000 }).map(async (_, index) => {
await vi.advanceTimersByTimeAsync(index)
expect(hydrateSpy).toHaveBeenCalledTimes(0)
}),
)
await vi.runAllTimersAsync()
expect(hydrateSpy).toHaveBeenCalledTimes(0)

hydrateSpy.mockRestore()
queryClient.clear()
Expand Down Expand Up @@ -365,4 +361,27 @@ describe('React hydration', () => {
hydrateSpy.mockRestore()
queryClient.clear()
})
})

test('should not hydrate queries if state is truthy and non-object', async () => {
const queryClient = createQueryClient()
const hydrateSpy = vi.spyOn(coreModule, 'hydrate')

function Page() {
return null
}

render(
<QueryClientProvider client={queryClient}>
<HydrationBoundary state='state'>
<Page />
</HydrationBoundary>
</QueryClientProvider>,
)

await vi.runAllTimersAsync()
expect(hydrateSpy).toHaveBeenCalledTimes(0)

hydrateSpy.mockRestore()
queryClient.clear()
})
})