Open History to see the last commit
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
25}
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
40}
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
58}
59β
60export type InternalHydrateProps = HydrateProps & {
61 h?: string
62 p?: () => Promise<void>
63}
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)
75}