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

Hydrate.tsx

75 lines1.8 KB

1import { GenericHydrate } from './GenericHydrate'
2import type {
3 HydrationStrategy as CoreHydrationStrategy,
4 HydrationPrefetchFunction,
5 HydrationPrefetchStrategy,
6 HydrationWhen,
7} from '@tanstack/start-client-core/hydration'
8import type * as Solid from 'solid-js'
9​
10export type {
11 HydrationInteractionEvent,
12 HydrationInteractionEvents,
13 HydrationPrefetchContext,
14 HydrationPrefetchFunction,
15 HydrationPrefetchStrategy,
16 HydrationPrefetchWaitReason,
17 HydrationWhen,
18} from '@tanstack/start-client-core/hydration'
19​
20export type SolidHydrationStrategy<
21 TWhen extends HydrationWhen = HydrationWhen,
22 TCanPrefetch extends boolean = boolean,
23> = CoreHydrationStrategy<TWhen, TCanPrefetch> & {
24 _h: (props: HydrateProps) => Solid.JSX.Element
26​
27export type HydrationStrategy<
28 TWhen extends HydrationWhen = HydrationWhen,
29 TCanPrefetch extends boolean = boolean,
30> = SolidHydrationStrategy<TWhen, TCanPrefetch>
31​
32export type HydrateWhen =
33 | SolidHydrationStrategy
34 | (() => SolidHydrationStrategy)
35​
36type HydrateCommonOptions = {
37 when: HydrateWhen
38 fallback?: Solid.JSX.Element
39 onHydrated?: () => void
41​
42export type HydrateOptions =
43 | (HydrateCommonOptions & {
44 prefetch?: never
45 split?: boolean
46 })
47 | (HydrateCommonOptions & {
48 prefetch: HydrationPrefetchStrategy
49 split?: true
50 })
51 | (HydrateCommonOptions & {
52 prefetch: HydrationPrefetchFunction
53 split?: boolean
54 })
55​
56export type HydrateProps = HydrateOptions & {
57 children: Solid.JSX.Element
59​
60export type InternalHydrateProps = HydrateProps & {
61 h?: string
62 p?: () => Promise<void>
64​
65/* @__NO_SIDE_EFFECTS__ */
66export function Hydrate(props: HydrateProps) {
67 if (
68 typeof props.when === 'function' ||
69 typeof props.prefetch === 'function'
70 ) {
71 return <GenericHydrate {...(props as InternalHydrateProps)} />
72 }
73​
74 return props.when._h(props)