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

RouterClient.tsx

43 lines1.2 KB

1import { hydrate } from '@tanstack/router-core/ssr/client'
2import { Await } from '../awaited'
3import { HeadContent } from '../HeadContent'
4import { RouterProvider } from '../RouterProvider'
5import type { AnyRouter } from '@tanstack/router-core'
6import type { JSXElement } from 'solid-js'
7​
8let hydrationPromise: Promise<void | Array<Array<void>>> | undefined
9​
10const Dummy = (props: { children?: JSXElement }) => <>{props.children}</>
11​
12export function RouterClient(props: { router: AnyRouter }) {
13 if (!hydrationPromise) {
14 if (!props.router.state.matches.length) {
15 hydrationPromise = hydrate(props.router)
16 } else {
17 hydrationPromise = Promise.resolve()
18 }
19 }
20 return (
21 <Await
22 promise={hydrationPromise}
23 children={() => (
24 <Dummy>
25 <Dummy>
26 <RouterProvider
27 router={props.router}
28 InnerWrap={(props) => (
29 <Dummy>
30 <Dummy>
31 <HeadContent />
32 {props.children}
33 </Dummy>
34 <Dummy />
35 </Dummy>
36 )}
37 />
38 </Dummy>
39 </Dummy>
40 )}
41 />
42 )