Skip to content

Commit 2362ae8

Browse files
authored
Merge branch 'main' into fix/hydration-boundary-double-fetch
2 parents 2faa447 + 984bfa6 commit 2362ae8

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

packages/preact-query/src/__tests__/useSuspenseQueries.test.tsx

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -855,4 +855,47 @@ describe('useSuspenseQueries 2', () => {
855855
consoleErrorSpy.mockRestore()
856856
process.env.NODE_ENV = envCopy
857857
})
858+
859+
it('should only suspend queries that are pending when some queries already have data', async () => {
860+
const key1 = queryKey()
861+
const key2 = queryKey()
862+
863+
queryClient.setQueryData(key1, 'cached')
864+
865+
function Page() {
866+
const [result1, result2] = useSuspenseQueries({
867+
queries: [
868+
{
869+
queryKey: key1,
870+
queryFn: () => sleep(QUERY_DURATION).then(() => 'data1'),
871+
},
872+
{
873+
queryKey: key2,
874+
queryFn: () => sleep(QUERY_DURATION).then(() => 'data2'),
875+
},
876+
],
877+
})
878+
879+
return (
880+
<div>
881+
<div>data1: {result1.data}</div>
882+
<div>data2: {result2.data}</div>
883+
</div>
884+
)
885+
}
886+
887+
const rendered = renderWithClient(
888+
queryClient,
889+
<Suspense fallback={<div>loading</div>}>
890+
<Page />
891+
</Suspense>,
892+
)
893+
894+
expect(rendered.getByText('loading')).toBeInTheDocument()
895+
896+
await vi.advanceTimersByTimeAsync(QUERY_DURATION)
897+
898+
expect(rendered.getByText('data1: cached')).toBeInTheDocument()
899+
expect(rendered.getByText('data2: data2')).toBeInTheDocument()
900+
})
858901
})

0 commit comments

Comments
 (0)