Skip to content

Commit 3d008f9

Browse files
committed
chore: add hydration debugger to solid ssr example
1 parent 6876385 commit 3d008f9

File tree

3 files changed

+106
-0
lines changed

3 files changed

+106
-0
lines changed

examples/solid/solid-start-streaming/src/root.css

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,3 +85,13 @@ p {
8585
font-weight: bold;
8686
flex-grow: 1;
8787
}
88+
89+
.example--table {
90+
padding: 0.5rem;
91+
}
92+
93+
.example--table th,
94+
.example--table td {
95+
padding: 4px 12px;
96+
white-space: nowrap;
97+
}

examples/solid/solid-start-streaming/src/root.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ export default function Root() {
4343
<A href="/deferred">Deferred</A>
4444
<A href="/mixed">Mixed</A>
4545
<A href="/with-error">With Error</A>
46+
<A href="/hydration">Hydration</A>
4647

4748
<Routes>
4849
<FileRoutes />
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import type { CreateQueryResult } from '@tanstack/solid-query'
2+
import { createQuery } from '@tanstack/solid-query'
3+
import { createSignal, Suspense } from 'solid-js'
4+
import { fetchUser } from '~/utils/api'
5+
import { NoHydration } from 'solid-js/web'
6+
import { Title } from 'solid-start'
7+
8+
export default function Hydration() {
9+
const query = createQuery(() => ({
10+
queryKey: ['user'],
11+
queryFn: () => fetchUser({ sleep: 500 }),
12+
deferStream: true,
13+
}))
14+
15+
const [initialQueryState] = createSignal(JSON.parse(JSON.stringify(query)))
16+
17+
return (
18+
<main>
19+
<Title>Solid Query - Hydration</Title>
20+
21+
<h1>Solid Query - Hydration Example</h1>
22+
23+
<div class="description">
24+
<p>
25+
Lists the query state as seen on the server, initial render on the
26+
client (right after hydration), and current client value. Ideally, if
27+
SSR is setup correctly, these values are exactly the same in all three
28+
contexts.
29+
</p>
30+
</div>
31+
32+
<button onClick={() => query.refetch()}>Refetch</button>
33+
34+
<table class="example example--table">
35+
<thead>
36+
<tr>
37+
<th>Context</th>
38+
<th>data.name</th>
39+
<th>isFetching</th>
40+
<th>isFetched</th>
41+
<th>isPending</th>
42+
<th>isRefetching</th>
43+
<th>isLoading</th>
44+
<th>isStale</th>
45+
<th>isSuccess</th>
46+
<th>fetchStatus</th>
47+
<th>dataUpdatedAt</th>
48+
</tr>
49+
</thead>
50+
51+
<tbody>
52+
<Suspense>
53+
<NoHydration>
54+
<QueryStateRow context="server" query={query} />
55+
</NoHydration>
56+
57+
<QueryStateRow
58+
context="client (initial render)"
59+
query={initialQueryState()!}
60+
/>
61+
62+
<QueryStateRow context="client" query={query} />
63+
</Suspense>
64+
</tbody>
65+
</table>
66+
</main>
67+
)
68+
}
69+
70+
type QueryState = CreateQueryResult<
71+
{
72+
id: string
73+
name: string
74+
queryTime: number
75+
},
76+
Error
77+
>
78+
79+
const QueryStateRow = (props: { context: string; query: QueryState }) => {
80+
return (
81+
<tr>
82+
<td>{props.context}</td>
83+
<td>{props.query.data?.name}</td>
84+
<td>{String(props.query.isFetching)}</td>
85+
<td>{String(props.query.isFetched)}</td>
86+
<td>{String(props.query.isPending)}</td>
87+
<td>{String(props.query.isRefetching)}</td>
88+
<td>{String(props.query.isLoading)}</td>
89+
<td>{String(props.query.isStale)}</td>
90+
<td>{String(props.query.isSuccess)}</td>
91+
<td>{String(props.query.fetchStatus)}</td>
92+
<td>{String(props.query.dataUpdatedAt)}</td>
93+
</tr>
94+
)
95+
}

0 commit comments

Comments
 (0)