Skip to content

Commit f98351a

Browse files
feat: deferred hydration
1 parent 13432ad commit f98351a

206 files changed

Lines changed: 23723 additions & 1151 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
---
2+
'@tanstack/react-start-client': minor
3+
'@tanstack/solid-start-client': minor
4+
'@tanstack/start-client-core': minor
5+
'@tanstack/start-plugin-core': minor
6+
'@tanstack/start-server-core': minor
7+
'@tanstack/router-core': patch
8+
'@tanstack/router-plugin': patch
9+
'@tanstack/router-utils': patch
10+
---
11+
12+
Add deferred Hydrate boundary support for TanStack Start.
13+
14+
Hydrate boundaries can now be code-split by the Start compiler, preload their generated client chunks, preserve server-rendered fallback HTML, and replay interaction-triggered events after hydration. The compiler integration now uses a Start-owned compiler plugin for Hydrate virtual modules across Vite and Rsbuild, with dev invalidation for generated virtual modules.
15+
16+
Shared AST utilities used by the router code-splitter and Hydrate virtual modules were moved into `@tanstack/router-utils` so both pipelines can retain referenced top-level declarations, unwrap local exports, and let dead-code elimination remove unused route module code.

‎benchmarks/bundle-size/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Each package has `minimal` and `full` scenarios:
1313
- `minimal`: Small route app with `__root` + index route that renders `hello world`
1414
- `full`: Same route shape plus a broad root-level harness that imports/uses the full hooks/components surface
1515
- Start `full` scenarios also exercise `createServerFn`, `createMiddleware`, and `useServerFn`
16+
- Start `deferred-hydration` scenarios match the minimal route shape and wrap the index route content in `Hydrate`
1617

1718
## Design Notes
1819

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createRouter } from '@tanstack/react-router'
2+
import { routeTree } from './routeTree.gen'
3+
4+
export function getRouter() {
5+
return createRouter({
6+
routeTree,
7+
scrollRestoration: true,
8+
})
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
HeadContent,
3+
Outlet,
4+
Scripts,
5+
createRootRoute,
6+
} from '@tanstack/react-router'
7+
8+
export const Route = createRootRoute({
9+
component: RootComponent,
10+
})
11+
12+
function RootComponent() {
13+
return (
14+
<html>
15+
<head>
16+
<HeadContent />
17+
</head>
18+
<body>
19+
<Outlet />
20+
<Scripts />
21+
</body>
22+
</html>
23+
)
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createFileRoute } from '@tanstack/react-router'
2+
import { Hydrate } from '@tanstack/react-start'
3+
import { visible } from '@tanstack/react-start/hydration'
4+
5+
export const Route = createFileRoute('/')({
6+
component: IndexComponent,
7+
})
8+
9+
function IndexComponent() {
10+
return (
11+
<Hydrate when={visible()}>
12+
<div>hello world</div>
13+
</Hydrate>
14+
)
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'vite'
2+
import viteReact from '@vitejs/plugin-react'
3+
import { tanstackStart } from '@tanstack/react-start/plugin/vite'
4+
5+
export default defineConfig({
6+
plugins: [tanstackStart(), viteReact()],
7+
})
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { createRouter } from '@tanstack/solid-router'
2+
import { routeTree } from './routeTree.gen'
3+
4+
export function getRouter() {
5+
return createRouter({
6+
routeTree,
7+
scrollRestoration: true,
8+
})
9+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import {
2+
HeadContent,
3+
Outlet,
4+
Scripts,
5+
createRootRoute,
6+
} from '@tanstack/solid-router'
7+
8+
export const Route = createRootRoute({
9+
component: RootComponent,
10+
})
11+
12+
function RootComponent() {
13+
return (
14+
<html>
15+
<head>
16+
<HeadContent />
17+
</head>
18+
<body>
19+
<Outlet />
20+
<Scripts />
21+
</body>
22+
</html>
23+
)
24+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { createFileRoute } from '@tanstack/solid-router'
2+
import { Hydrate } from '@tanstack/solid-start'
3+
import { visible } from '@tanstack/solid-start/hydration'
4+
5+
export const Route = createFileRoute('/')({
6+
component: IndexComponent,
7+
})
8+
9+
function IndexComponent() {
10+
return (
11+
<Hydrate when={visible()}>
12+
<div>hello world</div>
13+
</Hydrate>
14+
)
15+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { defineConfig } from 'vite'
2+
import solid from 'vite-plugin-solid'
3+
import { tanstackStart } from '@tanstack/solid-start/plugin/vite'
4+
5+
export default defineConfig({
6+
plugins: [tanstackStart(), solid({ ssr: true })],
7+
})

0 commit comments

Comments
 (0)