Skip to content

Commit 3178314

Browse files
docs: document shellComponent
1 parent fec3509 commit 3178314

File tree

2 files changed

+92
-0
lines changed

2 files changed

+92
-0
lines changed

docs/start/framework/react/selective-ssr.md

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,51 @@ root { ssr: undefined }
186186
For the first route with `ssr: false` or `ssr: 'data-only'`, the server will render the route's `pendingComponent` as a fallback. If `pendingComponent` isn't configured, the `defaultPendingComponent` will be rendered. If neither is configured, no fallback will be rendered.
187187

188188
On the client during hydration, this fallback will be displayed for at least `minPendingMs` (or `defaultPendingMinMs` if not configured), even if the route doesn't have `beforeLoad` or `loader` defined.
189+
190+
## How to disable SSR of the root route?
191+
192+
You can disable server side rendering of the root route component, however the `<html>` shell still needs to be rendered on the server. This shell is configured via the `shellComponent` property and takes a single property `children`. The `shellComponent` is always SSRed and is wrapping around the root `component`, the root `errorComponent` or the root `notFound` component respectively.
193+
194+
A minimal setup of a root route with disabled SSR for the route component looks like this:
195+
196+
```tsx
197+
import * as React from 'react'
198+
199+
import {
200+
HeadContent,
201+
Outlet,
202+
Scripts,
203+
createRootRoute,
204+
} from '@tanstack/react-router'
205+
206+
export const Route = createRootRoute({
207+
shellComponent: RootShell,
208+
component: RootComponent,
209+
errorComponent: () => <div>Error</div>,
210+
notFoundComponent: () => <div>Not found</>,
211+
ssr: false // or `defaultSsr: false` on the router
212+
})
213+
214+
function RootShell({ children }: { children: React.ReactNode }) {
215+
return (
216+
<html>
217+
<head>
218+
<HeadContent />
219+
</head>
220+
<body>
221+
{children}
222+
<Scripts />
223+
</body>
224+
</html>
225+
)
226+
}
227+
228+
function RootComponent() {
229+
return (
230+
<div>
231+
<h1>This component will be rendered on the client</h1>
232+
<Outlet />
233+
</div>
234+
)
235+
}
236+
```

docs/start/framework/solid/selective-ssr.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,3 +186,47 @@ root { ssr: undefined }
186186
For the first route with `ssr: false` or `ssr: 'data-only'`, the server will render the route's `pendingComponent` as a fallback. If `pendingComponent` isn't configured, the `defaultPendingComponent` will be rendered. If neither is configured, no fallback will be rendered.
187187

188188
On the client during hydration, this fallback will be displayed for at least `minPendingMs` (or `defaultPendingMinMs` if not configured), even if the route doesn't have `beforeLoad` or `loader` defined.
189+
190+
## How to disable SSR of the root route?
191+
192+
You can disable server side rendering of the root route component, however the `<html>` shell still needs to be rendered on the server. This shell is configured via the `shellComponent` property and takes a single property `children`. The `shellComponent` is always SSRed and is wrapping around the root `component`, the root `errorComponent` or the root `notFound` component respectively.
193+
194+
A minimal setup of a root route with disabled SSR for the route component looks like this:
195+
196+
```tsx
197+
import type * as Solid from 'solid-js'
198+
199+
import {
200+
HeadContent,
201+
Outlet,
202+
Scripts,
203+
createRootRoute,
204+
} from '@tanstack/solid-router'
205+
206+
export const Route = createRootRoute({
207+
shellComponent: RootShell,
208+
component: RootComponent,
209+
errorComponent: () => <div>Error</div>,
210+
notFoundComponent: () => <div>Not found</>,
211+
ssr: false // or `defaultSsr: false` on the router
212+
})
213+
214+
function RootShell({ children }: { children: Solid.JSX.Element }) {
215+
return (
216+
<>
217+
<HeadContent />
218+
{children}
219+
<Scripts />
220+
</>
221+
)
222+
}
223+
224+
function RootComponent() {
225+
return (
226+
<div>
227+
<h1>This component will be rendered on the client</h1>
228+
<Outlet />
229+
</div>
230+
)
231+
}
232+
```

0 commit comments

Comments
 (0)