Open History to see the last commit
1<script lang="ts">
2 import { onMount } from 'svelte'
3 import { setDbClientContext, useDbContext } from './db-context.js'
4 import type { DbClient } from '@tanstack/db'
5 import type { Snippet } from 'svelte'
6
7 let {
8 client,
9 hydrating = useDbContext()?.hydrating ?? false,
10 children,
11 }: {
12 client: DbClient
13 /** Set for a root initialized with Svelte hydrate(); nested providers inherit. */
14 hydrating?: boolean
15 children?: Snippet
16 } = $props()
17
18 // The host supplies hydration intent. New children after this provider's
19 // mount read live rows, even while transported server snapshots are retained.
20 let initialHydration = true
21 setDbClientContext(
22 () => client,
23 () => initialHydration && hydrating,
24 )
25 onMount(() => {
26 initialHydration = false
27 })
28</script>
29
30{@render children?.()}