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

client.tsx

32 lines1001 Bytes

1import { hydrateRoot } from 'react-dom/client'
2import { RouterClient } from '@tanstack/react-router/ssr/client'
3import { makeFixture } from './fixture'
4import type { HostHistory, HostObservation } from './fixture'
5​
6const history = JSON.parse(
7 new URL(location.href).searchParams.get(`history`)!,
8) as HostHistory
9const observations: Array<HostObservation> = [
10 { type: `entry`, at: performance.now() },
12window.streamViews = observations
13const fixture = makeFixture(`browser`, history, (observation) =>
14 observations.push(observation),
16window.streamFixture = fixture
17if (history.browserPreload) {
18 const hydrate = fixture.router.options.hydrate!
19 fixture.router.options.hydrate = async (state) => {
20 await hydrate(state)
21 await fixture.prepareBrowser()
22 }
24hydrateRoot(document, <RouterClient router={fixture.router} />, {
25 onRecoverableError(error) {
26 observations.push({
27 type: `recoverable-error`,
28 message: String(error),
29 at: performance.now(),
30 })
31 },
32})