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

client-entry-point.md

62 lines1.7 KB

1---
2id: client-entry-point
3title: Client Entry Point
4---
5​
6> [!NOTE]
7> The client entry point is **optional** out of the box. If not provided, TanStack Start will automatically handle the client entry point for you using the below as a default.
8​
9Getting our html to the client is only half the battle. Once there, we need to hydrate our client-side JavaScript once the route resolves to the client. We do this by hydrating the root of our application with the `StartClient` component:
10​
11```tsx
12// src/client.tsx
13import { hydrate } from 'solid-js/web'
14import { StartClient, hydrateStart } from '@tanstack/solid-start/client'
15​
16hydrateStart().then((router) => {
17 hydrate(() => <StartClient router={router} />, document)
18})
19```
20​
21This enables us to kick off client-side routing once the user's initial server request has fulfilled.
22​
23## Error Handling
24​
25You can wrap your client entry point with error boundaries to handle client-side errors gracefully:
26​
27```tsx
28// src/client.tsx
29import { StartClient } from '@tanstack/solid-start/client'
30import { hydrate } from 'solid-js/web'
31import { ErrorBoundary } from './components/ErrorBoundary'
32​
33hydrate(
34 () => (
35 <ErrorBoundary>
36 <StartClient />
37 </ErrorBoundary>
38 ),
39 document.body,
41```
42​
43## Development vs Production
44​
45You may want different behavior in development vs production:
46​
47```tsx
48// src/client.tsx
49import { StartClient } from '@tanstack/solid-start/client'
50import { hydrate } from 'solid-js/web'
51​
52const App = (
53 <>
54 {import.meta.env.DEV && <div>Development Mode</div>}
55 <StartClient />
56 </>
58​
59hydrate(() => <App />, document.body)
60```
61​
62The client entry point gives you full control over how your application initializes on the client side while working seamlessly with TanStack Start's server-side rendering.