Open History to see the last commit
1/**
2 * Streaming fixture for the SSR β hydration window tests.
3 *
4 * Two Loading boundaries: `header` resolves fast (its boundary content
5 * streams almost immediately), `feed` holds the stream open for ~250ms.
6 * This lets tests hydrate the fast section while the stream is still
7 * in flight and probe the window between cache priming and subscriber
8 * attach.
9 */
10import { Loading } from 'solid-js'
11import { QueryClientProvider, useQuery } from '@tanstack/solid-query'
12import type { QueryClient } from '@tanstack/solid-query'
13β
14export interface StreamCounts {
15 header: number
16 feed: number
17}
18β
19export interface StreamAppProps {
20 client: QueryClient
21 source: 'server' | 'client'
22 counts: StreamCounts
23}
24β
25const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms))
26β
27function HeaderQuery(props: StreamAppProps) {
28 const query = useQuery(() => ({
29 queryKey: ['header'],
30 queryFn: async () => {
31 props.counts.header++
32 await sleep(5)
33 return `header-${props.source}`
34 },
35 staleTime: 60_000,
36 }))
37 return <span id="header">{query.data}</span>
38}
39β
40function FeedQuery(props: StreamAppProps) {
41 const query = useQuery(() => ({
42 queryKey: ['feed'],
43 queryFn: async () => {
44 props.counts.feed++
45 await sleep(250)
46 return `feed-${props.source}`
47 },
48 staleTime: 60_000,
49 }))
50 return <span id="feed">{query.data}</span>
51}
52β
53export function StreamApp(props: StreamAppProps) {
54 return (
55 <QueryClientProvider client={props.client}>
56 <div>
57 <Loading fallback={<div>loading-header</div>}>
58 <HeaderQuery {...props} />
59 </Loading>
60 <Loading fallback={<div>loading-feed</div>}>
61 <FeedQuery {...props} />
62 </Loading>
63 </div>
64 </QueryClientProvider>
65 )
66}