perf(react-router): reduce component nesting per route match #8594
main fromrefs/pull/8594/head·merged by Sheraff(GitHub profile, opens in a new tab) Fiber traversal has been appearing in a number of traces I ran recently. So we should try and watch out for unnecessary component nesting.
This PR removes 2 unnecessary component layers in Match (i.e. per route match)
Summary by CodeRabbit#
- Refactor
- Simplified route rendering, with root-route shells continuing to wrap page content and scroll restoration when configured.
- When no root-route shell is configured, page content and scroll restoration render directly within the route context. These adjustments streamline how route content is composed without changing the available routing features.
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router
View your CI Pipeline Execution ↗ for commit fca385e3116ca61f49fb3f2671c57e55a0cf054c
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 17m 29s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 20s View ↗
☁️ Nx Cloud last updated this comment at
2026-10-03 20:25:35UTCNavigate 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:
b8db5cf4-0c56-4399-a204-2a671132d311
📥 Commits
Reviewing files that changed from the base of the PR and between a0c39b91d9fb8511abf7cdadf497709bcd682826 and fca385e3116ca61f49fb3f2671c57e55a0cf054c.
📒 Files selected for processing (1)
packages/react-router/src/Match.tsx
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
📝 Walkthrough
Walkthrough#
Matchnow uses a shared rendering function for server and client matches. Root shell rendering occurs inside the match context provider when a root shell exists. A Changesets entry declares a patch release.Changes#
Match rendering
Layer / File(s) Summary Match rendering and composition
packages/react-router/src/Match.tsx,.changeset/cold-icons-teach.mdThe server and client branches pass their match to matchView. When a root route has a shell component, it wraps route content and scroll restoration inside the match context provider. Otherwise, those children render directly in the provider. The Changesets entry declares a patch release for@tanstack/react-router.Priority: ⬇️ Low
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Refactor
Merge Risk: ⚪ Minimal · up to
fca38No concrete rendering or context regression is established by this change. It appears mergeable after normal checks.
Architecture Summary#
Architecture risk: 🔵 Low · up to
fca38The change affects 1 system.
Changed systems:
packages/react-routerArchitecture concerns No architecture-level concerns identified.
Review details
Systems and components
- observed — packages/react-router (library) was modified; 1 changed file maps to changed impact.
Before / after behavior
- observed — Modified behavior in packages/react-router/src/Match.tsx: The server and client branches now call a shared
matchViewfunction; the separateMatchViewcomponent and its props wrapper were removed. Client selection still usesuseSelector, with the non-null assertion moved to the selected match. - observed — Modified behavior in packages/react-router/src/Match.tsx: Root shell selection now directly checks for a root route’s shell component. When present, it wraps content and scroll restoration inside the match context provider; when absent, those children render directly inside the provider rather than through a fragment. The shell and route boundaries continue sharing the match context.
- observed — Modified behavior in .changeset/cold-icons-teach.md: Adds a Changesets entry marking
@tanstack/react-routerfor a patch release and describing reduced component nesting per route match.
🚥 Pre-merge checks | ✅ 4 | ❌ 1
❌ Failed checks (1 warning)#
Check name Status Explanation Resolution Docstring Coverage ⚠️ Warning 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 1 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold. ✅ Passed checks (4 passed)
Check name Status Explanation Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request. Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request. Title check ✅ Passed The title clearly summarizes the main change: reducing component nesting in React Router route matches. Description check ✅ Passed The description explains the change and its motivation. It does not include the template’s checklist or release impact section, but the changeset entry confirms a patch release is planned. - Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
- Commit to this branch
- Create a new PR
🧪 Generate unit tests (beta)
- Commit to this branch
- Create a new PR
- Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
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.
Comment `@coderabbitai help` to get the list of available commands.🚀 Changeset Version Preview#
3 package(s) bumped directly, 10 bumped as dependents.
🟩 Patch bumps#
Package Version Reason @tanstack/react-router1.170.41 → 1.170.42 Changeset @tanstack/solid-router1.170.38 → 1.170.39 Changeset @tanstack/vue-router1.170.37 → 1.170.38 Changeset @tanstack/react-start1.168.60 → 1.168.61 Dependent @tanstack/react-start-client1.168.39 → 1.168.40 Dependent @tanstack/react-start-rsc0.1.59 → 0.1.60 Dependent @tanstack/react-start-server1.167.46 → 1.167.47 Dependent @tanstack/solid-start1.168.57 → 1.168.58 Dependent @tanstack/solid-start-client1.168.37 → 1.168.38 Dependent @tanstack/solid-start-server1.167.44 → 1.167.45 Dependent @tanstack/vue-start1.168.56 → 1.168.57 Dependent @tanstack/vue-start-client1.167.40 → 1.167.41 Dependent @tanstack/vue-start-server1.167.44 → 1.167.45 Dependent Bundle Size Benchmarks#
- Commit:
4d41ec034e44 - Measured at:
2026-10-03T20:08:49.116Z - Baseline source:
history:1f0f20a3206a - Dashboard: bundle-size history
The following scenarios have bundle-size changes compared with the baseline:
Scenario Current (gzip) Initial (gzip) Raw Brotli Trend react-router.minimal83.9 KiB
-9 B83.8 KiB
-10 B261.4 KiB
-27 B73.2 KiB
+91 B▁▁▁▇▇▇█████▅
react-router.full87.5 KiB
-5 B87.4 KiB
-8 B273.2 KiB
-27 B76.4 KiB
+48 B▂▂▁▇▇▇███▇▇▆
react-start.minimal96.8 KiB
-9 B96.6 KiB
-9 B302.3 KiB
-27 B84.0 KiB
+17 B▂▂▁▆▆▆█████▆
react-start.query-integration104.2 KiB
+1 B104.1 KiB
+1 B329.0 KiB
-27 B90.5 KiB
+26 B▃▃▁███▇▇▇▇▇█
react-start.deferred-hydration97.5 KiB
-7 B96.7 KiB
-10 B303.7 KiB
-27 B84.8 KiB
+71 B▂▂▁▆▆▆███▇▇▅
react-start.full99.9 KiB
-8 B99.8 KiB
-11 B312.1 KiB
-27 B86.7 KiB
-57 B▂▂▁▅▅▅▆████▆
react-start.rsbuild.minimal100.3 KiB
-2 B100.2 KiB
-2 B313.4 KiB
-39 B86.7 KiB
+56 B▁▁▁▇▇▇████▇▇
react-start.rsbuild.minimal-iife100.7 KiB
0 B100.6 KiB
0 B314.3 KiB
-39 B87.0 KiB
-50 B▂▂▁▇▇▇█████
react-start.rsbuild.full103.6 KiB
+1 B103.4 KiB
+1 B323.5 KiB
-39 B89.3 KiB
-69 B▂▂▁▄▄▄▅█████
Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.
- Commit:
More 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@8594@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@8594@tanstack/eslint-plugin-start
npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8594@tanstack/history
npm i https://pkg.pr.new/@tanstack/history@8594@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@8594@tanstack/react-router
npm i https://pkg.pr.new/@tanstack/react-router@8594@tanstack/react-router-devtools
npm i https://pkg.pr.new/@tanstack/react-router-devtools@8594@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@8594@tanstack/react-start
npm i https://pkg.pr.new/@tanstack/react-start@8594@tanstack/react-start-client
npm i https://pkg.pr.new/@tanstack/react-start-client@8594@tanstack/react-start-rsc
npm i https://pkg.pr.new/@tanstack/react-start-rsc@8594@tanstack/react-start-server
npm i https://pkg.pr.new/@tanstack/react-start-server@8594@tanstack/router-cli
npm i https://pkg.pr.new/@tanstack/router-cli@8594@tanstack/router-core
npm i https://pkg.pr.new/@tanstack/router-core@8594@tanstack/router-devtools
npm i https://pkg.pr.new/@tanstack/router-devtools@8594@tanstack/router-devtools-core
npm i https://pkg.pr.new/@tanstack/router-devtools-core@8594@tanstack/router-generator
npm i https://pkg.pr.new/@tanstack/router-generator@8594@tanstack/router-plugin
npm i https://pkg.pr.new/@tanstack/router-plugin@8594@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@8594@tanstack/router-utils
npm i https://pkg.pr.new/@tanstack/router-utils@8594@tanstack/router-vite-plugin
npm i https://pkg.pr.new/@tanstack/router-vite-plugin@8594@tanstack/solid-router
npm i https://pkg.pr.new/@tanstack/solid-router@8594@tanstack/solid-router-devtools
npm i https://pkg.pr.new/@tanstack/solid-router-devtools@8594@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8594@tanstack/solid-start
npm i https://pkg.pr.new/@tanstack/solid-start@8594@tanstack/solid-start-client
npm i https://pkg.pr.new/@tanstack/solid-start-client@8594@tanstack/solid-start-server
npm i https://pkg.pr.new/@tanstack/solid-start-server@8594@tanstack/start-client-core
npm i https://pkg.pr.new/@tanstack/start-client-core@8594@tanstack/start-fn-stubs
npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8594@tanstack/start-plugin-core
npm i https://pkg.pr.new/@tanstack/start-plugin-core@8594@tanstack/start-server-core
npm i https://pkg.pr.new/@tanstack/start-server-core@8594@tanstack/start-static-server-functions
npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8594@tanstack/start-storage-context
npm i https://pkg.pr.new/@tanstack/start-storage-context@8594@tanstack/valibot-adapter
npm i https://pkg.pr.new/@tanstack/valibot-adapter@8594@tanstack/virtual-file-routes
npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8594@tanstack/vue-router
npm i https://pkg.pr.new/@tanstack/vue-router@8594@tanstack/vue-router-devtools
npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8594@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8594@tanstack/vue-start
npm i https://pkg.pr.new/@tanstack/vue-start@8594@tanstack/vue-start-client
npm i https://pkg.pr.new/@tanstack/vue-start-client@8594@tanstack/vue-start-server
npm i https://pkg.pr.new/@tanstack/vue-start-server@8594@tanstack/zod-adapter
npm i https://pkg.pr.new/@tanstack/zod-adapter@8594commit:
fca385eMerging this PR will degrade performance by 22.79%#
: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❌ 1 (👁 1)regressed benchmark✅ 189untouched benchmarks⏩ 3skipped benchmarks1Performance Changes#
Mode Benchmark BASEHEADEfficiency ⚡ Simulation client-control-flow navigation loop (react)99.3 ms 90.7 ms +9.42% 👁 Memory mem server streaming-peak chunked (react)349.7 KB 641.9 KB -45.52% Tip
Curious why performance improved? Comment
@codspeedbot explain why performance improvedon this PR, or directly use the CodSpeed MCP with your agent.
Comparingperf-react-router-reduce-component-nesting(fca385e) withmain(1f0f20a)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) closed this
Sign in to join this conversation.
🦋 Changeset detected#
Latest commit: fca385e3116ca61f49fb3f2671c57e55a0cf054c
The changes in this PR will be included in the next version bump.
This PR includes changesets to release 5 packages
Not sure what this means? Click here to learn what changesets are.
Click here if you're a maintainer who wants to add another changeset to this PR