Open History to see the last commit
1/**
2 * Streaming SSR entry for the hydration window tests. Renders StreamApp with
3 * renderToStream, capturing each written chunk with a timestamp so the test
4 * can replay the stream in phases (shell + fast boundary first, slow boundary
5 * later) and probe the window in between.
6 */
7import { renderToStream } from '@solidjs/web'
8import { QueryClient } from '@tanstack/solid-query'
9import { StreamApp } from './StreamApp'
10import type { Query } from '@tanstack/solid-query'
11import type { StreamCounts } from './StreamApp'
12β
13const client = new QueryClient()
14const counts: StreamCounts = { header: 0, feed: 0 }
15β
16// The provider clears the cache when the render disposes (the SSR
17// teardown), so query states are recorded live off cache events rather
18// than read back after completion.
19const snapshots = new Map<
20 string,
21 { queryKey: unknown; queryHash: string; state: unknown }
22>()
23client.getQueryCache().subscribe((event) => {
24 if (event.type === 'removed') return
25 const query: Query<any, any, any, any> = event.query
26 snapshots.set(query.queryHash, {
27 queryKey: query.queryKey,
28 queryHash: query.queryHash,
29 state: query.state,
30 })
31})
32β
33const start = Date.now()
34const chunks: Array<{ t: number; payload: string }> = []
35β
36await new Promise<void>((resolve) => {
37 renderToStream(() => (
38 <StreamApp client={client} source="server" counts={counts} />
39 )).pipe({
40 write(payload: string) {
41 chunks.push({ t: Date.now() - start, payload })
42 },
43 end() {
44 resolve()
45 },
46 })
47})
48β
49const cacheEmptyAfterDispose = client.getQueryCache().getAll().length === 0
50β
51console.log(
52 JSON.stringify({
53 chunks,
54 counts,
55 queries: [...snapshots.values()],
56 cacheEmptyAfterDispose,
57 }),
58)