Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

entry-client.tsx

60 lines1.6 KB

1/**
2 * Client entry for the hydration tests. Bundled with the hydratable DOM
3 * transform and imported dynamically by the jsdom test, which then calls
4 * `mount()` against the server-rendered markup. Factories return fresh
5 * QueryClient/counters per call so multiple tests can share the bundle.
6 */
7import { hydrate } from '@solidjs/web'
8import { createSignal } from 'solid-js'
9import { QueryClient } from '@tanstack/solid-query'
10import { App } from './App'
11import { StreamApp } from './StreamApp'
12import type { FetchCounts } from './App'
13import type { StreamCounts } from './StreamApp'
14​
15export function createApp() {
16 const queryClient = new QueryClient()
17 const counts: FetchCounts = {
18 fresh: 0,
19 stale: 0,
20 placeholder: 0,
21 prefetched: 0,
22 }
23 const [lateMount, setLateMount] = createSignal(false)
24 return {
25 queryClient,
26 counts,
27 /** Mount the subtree the server never rendered (see `LateConsumer`). */
28 showLate: () => setLateMount(true),
29 mount(container: HTMLElement): () => void {
30 return hydrate(
31 () => (
32 <App
33 client={queryClient}
34 source="client"
35 counts={counts}
36 lateMount={lateMount}
37 />
38 ),
39 container,
40 )
41 },
42 }
44​
45export function createStreamApp() {
46 const queryClient = new QueryClient()
47 const counts: StreamCounts = { header: 0, feed: 0 }
48 return {
49 queryClient,
50 counts,
51 mount(container: HTMLElement): () => void {
52 return hydrate(
53 () => (
54 <StreamApp client={queryClient} source="client" counts={counts} />
55 ),
56 container,
57 )
58 },
59 }