perf(router-core): hydrate without awaiting code-split component chunks #8484
main fromrefs/pull/8484/head·opened 🎯 Changes#
hydrate() awaits loadRouteChunk() for every committed match before setMatches. RouterClient and StartClient render <Await> on that promise, so the React root commits nothing until the whole component closure of the matched routes has downloaded. That includes chrome whose code already sits in the entry chunk, such as a header in the root route. A click on a header <Link> in that window is a native document navigation.
We measured the cost on a production Start app on @tanstack/router-core@1.171.32. The table shows the root commit time, median of 3 runs, at 4x CPU slowdown with 150 ms RTT and 1.6 Mbps:
| Page | Awaiting chunks | Without the wait |
|---|---|---|
| Home | 4484 ms | 3375 ms |
| Search results | 4969 ms | 3825 ms |
| Detail page | 6237 ms | 3890 ms |
| Login | 3991 ms | 3372 ms |
The route body still waits for its own chunks. The bytes loaded before the commit do not change.
React does not need the wait. A code-split component is a lazyRouteComponent, which suspends on its first render. React keeps the server HTML of a dehydrated Suspense boundary until the promise resolves and does not render the fallback. The root Outlet always puts the child match inside such a boundary.
This PR keeps the loads starting in hydrate() and skips the wait when the router sets _hydrateWithoutComponentChunks. Only the React Router sets it. Vue's lazyRouteComponent renders an empty <div> until its chunk arrives, so Vue must keep the wait. I have not verified Solid's lazy() path through hydration, so Solid also keeps it. Either adapter can opt in later with one line.
A lane with a lazyFn route whose options are not merged (route.lazyFn && route._lazy !== true) still waits for every chunk. Such a route has no component yet and would render <Outlet /> in its place, which is a hydration mismatch. The wait could later be scoped to that route's subtree.
Failure path. React's lazyRouteComponent.preload never rejects. It records the error and throws it on render, where a module-not-found error reloads the document once (guarded in sessionStorage) and any other error goes to the route's error boundary. So for code-split components the failure path does not change. The one change is a hand-written component whose preload rejects. Before, hydrate() called retryFrom on that match. Now the component renders as is, because nothing awaits its preload. Lanes that still wait keep retryFrom.
Tests.
packages/react-router/tests/hydration-component-chunks.test.tsx, "commits the matches before a code-split component chunk arrives". AlazyRouteComponentimport is held pending.hydrate()resolves, the matches commit,hydrateRootkeeps the server HTML byte for byte before and after the import resolves, andonRecoverableErroris not called. Onmainthis test fails withexpected 'waiting' to be 'hydrated'.- The same file, "waits for lazy route options before committing the matches". A pending
lazyFnkeepshydrate()waiting until the options merge. This test passes onmaintoo and guards the kept wait. packages/router-core/tests/hydration-component-chunks.test.tschecks both flag values against a component with a pendingpreload. Without the flaghydrate()waits, and with the flag it resolves. The flag case fails onmain.
I did not find a router option that fits this. The behavior depends on the renderer, not on the app, so I set it in the adapter.
✅ Checklist#
- I have followed the steps in the Contributing guide.
- I have tested code changes locally with the relevant test commands, or tests do not apply to this pull request.
- I fully understand the code in this pull request, including any code generated with AI assistance.
Local runs, all exit 0: test:unit, test:types, test:eslint, build and test:build for @tanstack/router-core and @tanstack/react-router, and test:unit for @tanstack/react-start-client. I did not run the e2e suites.
🚀 Release Impact#
- This change affects published code, and I have generated a changeset.
- This change is docs/CI/dev-only (no release).
Summary by CodeRabbit#
- New Features
- React applications can now complete hydration while a code-split route component is still loading. The server-rendered content remains visible until the component is ready.
- Bug Fixes
- Hydration continues to wait for route options that have not yet resolved.
- Solid and Vue hydration behavior is unchanged.
- 1
View your CI Pipeline Execution ↗ for commit da70ff35e814fc6e91e6636f808a5ba5ac264dca
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 13m 7s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 2m 7s View ↗
☁️ Nx Cloud last updated this comment at
2026-09-23 15:43:10UTCMore templates
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-router-react-example-basic-authjs
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-rsbuild
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-example-next-migration
- tanstack-start-example-rscs
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-vue-example-basic-jsx
- tanstack-router-vue-example-basic-file-based-jsx
- tanstack-router-vue-example-basic-file-based-sfc
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-authenticated-routes-firebase
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-default-search-params
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-basic-virtual-file-based
- tanstack-router-solid-example-basic-virtual-inside-file-based
- tanstack-router-solid-example-deferred-data
- tanstack-router-solid-i18n-paraglide
- tanstack-router-solid-example-kitchen-sink
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-large-file-based
- tanstack-router-solid-example-location-masking
- tanstack-router-solid-example-navigation-blocking
- tanstack-router-solid-example-quickstart
- tanstack-router-solid-example-quickstart-esbuild-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-router-solid-example-quickstart-rspack-file-based
- tanstack-router-solid-example-quickstart-webpack-file-based
- @tanstack/router-solid-mono-simple
- router-solid-mono-simple-lazy
- router-solid-monorepo-solid-query
- tanstack-router-solid-example-scroll-restoration
- tanstack-solid-router-search-validator-adapters
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-authjs
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-solid-start-example-counter
- tanstack-solid-start-i18n-paraglide
- tanstack-solid-start-example-large
- tanstack-solid-start-streaming-data-from-server-functions
- tanstack-solid-start-example-supabase-basic
- tanstack-solid-start-tailwind-v4
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-solid-example-with-trpc
@tanstack/arktype-adapter
npm i https://pkg.pr.new/@tanstack/arktype-adapter@8484@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@8484@tanstack/eslint-plugin-start
npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8484@tanstack/history
npm i https://pkg.pr.new/@tanstack/history@8484@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@8484@tanstack/react-router
npm i https://pkg.pr.new/@tanstack/react-router@8484@tanstack/react-router-devtools
npm i https://pkg.pr.new/@tanstack/react-router-devtools@8484@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@8484@tanstack/react-start
npm i https://pkg.pr.new/@tanstack/react-start@8484@tanstack/react-start-client
npm i https://pkg.pr.new/@tanstack/react-start-client@8484@tanstack/react-start-rsc
npm i https://pkg.pr.new/@tanstack/react-start-rsc@8484@tanstack/react-start-server
npm i https://pkg.pr.new/@tanstack/react-start-server@8484@tanstack/router-cli
npm i https://pkg.pr.new/@tanstack/router-cli@8484@tanstack/router-core
npm i https://pkg.pr.new/@tanstack/router-core@8484@tanstack/router-devtools
npm i https://pkg.pr.new/@tanstack/router-devtools@8484@tanstack/router-devtools-core
npm i https://pkg.pr.new/@tanstack/router-devtools-core@8484@tanstack/router-generator
npm i https://pkg.pr.new/@tanstack/router-generator@8484@tanstack/router-plugin
npm i https://pkg.pr.new/@tanstack/router-plugin@8484@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@8484@tanstack/router-utils
npm i https://pkg.pr.new/@tanstack/router-utils@8484@tanstack/router-vite-plugin
npm i https://pkg.pr.new/@tanstack/router-vite-plugin@8484@tanstack/solid-router
npm i https://pkg.pr.new/@tanstack/solid-router@8484@tanstack/solid-router-devtools
npm i https://pkg.pr.new/@tanstack/solid-router-devtools@8484@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8484@tanstack/solid-start
npm i https://pkg.pr.new/@tanstack/solid-start@8484@tanstack/solid-start-client
npm i https://pkg.pr.new/@tanstack/solid-start-client@8484@tanstack/solid-start-server
npm i https://pkg.pr.new/@tanstack/solid-start-server@8484@tanstack/start-client-core
npm i https://pkg.pr.new/@tanstack/start-client-core@8484@tanstack/start-fn-stubs
npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8484@tanstack/start-plugin-core
npm i https://pkg.pr.new/@tanstack/start-plugin-core@8484@tanstack/start-server-core
npm i https://pkg.pr.new/@tanstack/start-server-core@8484@tanstack/start-static-server-functions
npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8484@tanstack/start-storage-context
npm i https://pkg.pr.new/@tanstack/start-storage-context@8484@tanstack/valibot-adapter
npm i https://pkg.pr.new/@tanstack/valibot-adapter@8484@tanstack/virtual-file-routes
npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8484@tanstack/vue-router
npm i https://pkg.pr.new/@tanstack/vue-router@8484@tanstack/vue-router-devtools
npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8484@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8484@tanstack/vue-start
npm i https://pkg.pr.new/@tanstack/vue-start@8484@tanstack/vue-start-client
npm i https://pkg.pr.new/@tanstack/vue-start-client@8484@tanstack/vue-start-server
npm i https://pkg.pr.new/@tanstack/vue-start-server@8484@tanstack/zod-adapter
npm i https://pkg.pr.new/@tanstack/zod-adapter@8484commit:
da70ff3Could you give me a human-readable TL;DR of this change? If i understand correctly we don't await the chunks during hydration (unless they are explicitly lazy) because they are not required for the hydration (they will simply load later, in render, and cause a suspense)
The failure path you are describing, if i understand correctly, is that we're not catching a failed lazy chunk load during hydration anymore, is that right?
Could you enumerate the setups that are impacted and those that aren't? (stuff like auto code splitting, manual code splitting, custom preload, explicit
.lazy...)it'd be interesting to see if we can apply the same logic to Vue and/or Solid. We don't like to advance 1 adapter and leave the other 2 behind (if there isn't a good reason to). And as a bonus if we can apply this to all 3, we can remove
_hydrateWithoutComponentChunkscompletely.also this is interesting
The wait could later be scoped to that route's subtree
does that make the code much more complex? we're trying not to add too many bytes, but i could see that being quite nice for some apps
Merging this PR will improve performance by 3.63%#
:warning: Different runtime environments detected
Some benchmarks with significant performance changes were compared across different runtime environments, which may affect the accuracy of the results.
⚡ 1improved benchmark✅ 188untouched benchmarks⏩ 3skipped benchmarks1Performance Changes#
Mode Benchmark BASEHEADEfficiency ⚡ Memory mem server error-paths unmatched (react)889.3 KB 858.2 KB +3.63% Tip
Curious why performance improved? Comment
@codspeedbot explain why performance improvedon this PR, or directly use the CodSpeed MCP with your agent.
ComparingTarek-kharsa:perf/hydrate-without-awaiting-component-chunks(da70ff3) withmain(fe7f1fd)Footnotes#
-
3 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
Sheraff(GitHub profile, opens in a new tab) assignedSheraff
Moved to #8577 from my personal account. Same change, rebased on main.
Tarek-kharsa(GitHub profile, opens in a new tab) closed this
Sign in to join this conversation.
Navigate logical layers of code changes, visualize relationships, and explore their blast radius.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Repository: TanStack/router/.coderabbit.yaml
Review profile: CHILL
Plan: Advanced
Run ID:
d085f99a-9554-44da-ab10-4c1c3dbada87📥 Commits
Reviewing files that changed from the base of the PR and between fe7f1fd0e6ef73c3f341dd2338b406749538a85d and da70ff35e814fc6e91e6636f808a5ba5ac264dca.
📒 Files selected for processing (6)
.changeset/hydrate-without-component-chunks.mdpackages/react-router/src/router.tspackages/react-router/tests/hydration-component-chunks.test.tsxpackages/router-core/src/load-client.tspackages/router-core/src/router.tspackages/router-core/tests/hydration-component-chunks.test.tsIncluded review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
React Router now allows hydration to commit matches before lazy route component chunks load. Router Core still waits for unresolved lazy route options and retains chunk waiting by default. Tests cover both behaviors and verify that React hydration preserves the server HTML.
Changes#
Hydration behavior
packages/router-core/src/router.ts,packages/router-core/src/load-client.ts,packages/react-router/src/router.ts,packages/router-core/tests/hydration-component-chunks.test.ts,packages/react-router/tests/hydration-component-chunks.test.tsx,.changeset/hydrate-without-component-chunks.mdPriority: ⬇️ Low
Estimated code review effort: 3 (Moderate) | ~20 minutes
Change: Feature
Suggested reviewers:
schiller-manuelMerge Risk: ⚪ Minimal · up to
da70fReact apps can now finish hydrating before code-split route components download. Those routes keep showing their server-rendered HTML until the chunk arrives. Solid and Vue are unchanged, and routes that still load their options lazily continue to wait. No confirmed defect blocks merging. It is still worth checking how a failed chunk download behaves during hydration, because that path now surfaces as a render-time error instead of a hydration-time retry.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
✅ Passed checks (4 passed)
Full details: Docstring Coverage
Explanation
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 10 functions across 5 files. (1 skipped: 1 unsupported.)
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share