Skip to content
Source
Sign inSign up
TanStack/router

perf(react-router): reduce component nesting per route match #8594

MergedSheraff(GitHub profile, opens in a new tab)merged 2 commits intomain fromrefs/pull/8594/headmerged 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. changeset-bot[bot](GitHub profile, opens in a new tab)commented

      🦋 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
      NameType
      @tanstack/react-routerPatch
      @tanstack/react-start-clientPatch
      @tanstack/react-start-rscPatch
      @tanstack/react-start-serverPatch
      @tanstack/react-startPatch

      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

    2. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router

    3. nx-cloud[bot](GitHub profile, opens in a new tab)commented

      View your CI Pipeline Execution ↗ for commit fca385e3116ca61f49fb3f2671c57e55a0cf054c

      CommandStatusDurationResult
      nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded17m 29sView ↗
      nx run-many --target=build --exclude=examples/*...✅ Succeeded1m 20sView ↗

      ☁️ Nx Cloud last updated this comment at 2026-10-03 20:25:35 UTC

    4. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review in Change Stack →

      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: 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

      Match now 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.md
      The 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 fca38

      No concrete rendering or context regression is established by this change. It appears mergeable after normal checks.

      Architecture Summary

      Architecture risk: 🔵 Low · up to fca38

      The change affects 1 system.

      Changed systems: packages/react-router

      Architecture 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 matchView function; the separate MatchView component and its props wrapper were removed. Client selection still uses useSelector, 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-router for a patch release and describing reduced component nesting per route match.
      🚥 Pre-merge checks | ✅ 4 | ❌ 1

      ❌ Failed checks (1 warning)

      Check nameStatusExplanationResolution
      Docstring Coverage⚠️ WarningDocstring 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 nameStatusExplanation
      Linked Issues check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes check✅ PassedCheck skipped because no linked issues were found for this pull request.
      Title check✅ PassedThe title clearly summarizes the main change: reducing component nesting in React Router route matches.
      Description check✅ PassedThe 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.

      ❤️ Share
      Comment `@coderabbitai help` to get the list of available commands.
    5. github-actions[bot](GitHub profile, opens in a new tab)commented

      🚀 Changeset Version Preview

      3 package(s) bumped directly, 10 bumped as dependents.

      🟩 Patch bumps

      PackageVersionReason
      @tanstack/react-router1.170.41 → 1.170.42Changeset
      @tanstack/solid-router1.170.38 → 1.170.39Changeset
      @tanstack/vue-router1.170.37 → 1.170.38Changeset
      @tanstack/react-start1.168.60 → 1.168.61Dependent
      @tanstack/react-start-client1.168.39 → 1.168.40Dependent
      @tanstack/react-start-rsc0.1.59 → 0.1.60Dependent
      @tanstack/react-start-server1.167.46 → 1.167.47Dependent
      @tanstack/solid-start1.168.57 → 1.168.58Dependent
      @tanstack/solid-start-client1.168.37 → 1.168.38Dependent
      @tanstack/solid-start-server1.167.44 → 1.167.45Dependent
      @tanstack/vue-start1.168.56 → 1.168.57Dependent
      @tanstack/vue-start-client1.167.40 → 1.167.41Dependent
      @tanstack/vue-start-server1.167.44 → 1.167.45Dependent
    6. github-actions[bot](GitHub profile, opens in a new tab)commented

      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:

      ScenarioCurrent (gzip)Initial (gzip)RawBrotliTrend
      react-router.minimal83.9 KiB
      -9 B
      83.8 KiB
      -10 B
      261.4 KiB
      -27 B
      73.2 KiB
      +91 B
      ▁▁▁▇▇▇█████▅
      react-router.full87.5 KiB
      -5 B
      87.4 KiB
      -8 B
      273.2 KiB
      -27 B
      76.4 KiB
      +48 B
      ▂▂▁▇▇▇███▇▇▆
      react-start.minimal96.8 KiB
      -9 B
      96.6 KiB
      -9 B
      302.3 KiB
      -27 B
      84.0 KiB
      +17 B
      ▂▂▁▆▆▆█████▆
      react-start.query-integration104.2 KiB
      +1 B
      104.1 KiB
      +1 B
      329.0 KiB
      -27 B
      90.5 KiB
      +26 B
      ▃▃▁███▇▇▇▇▇█
      react-start.deferred-hydration97.5 KiB
      -7 B
      96.7 KiB
      -10 B
      303.7 KiB
      -27 B
      84.8 KiB
      +71 B
      ▂▂▁▆▆▆███▇▇▅
      react-start.full99.9 KiB
      -8 B
      99.8 KiB
      -11 B
      312.1 KiB
      -27 B
      86.7 KiB
      -57 B
      ▂▂▁▅▅▅▆████▆
      react-start.rsbuild.minimal100.3 KiB
      -2 B
      100.2 KiB
      -2 B
      313.4 KiB
      -39 B
      86.7 KiB
      +56 B
      ▁▁▁▇▇▇████▇▇
      react-start.rsbuild.minimal-iife100.7 KiB
      0 B
      100.6 KiB
      0 B
      314.3 KiB
      -39 B
      87.0 KiB
      -50 B
      ▂▂▁▇▇▇█████
      react-start.rsbuild.full103.6 KiB
      +1 B
      103.4 KiB
      +1 B
      323.5 KiB
      -39 B
      89.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.

    7. pkg-pr-new[bot](GitHub profile, opens in a new tab)commented
      More templates

      @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@8594

      commit: fca385e

    8. codspeed[bot](GitHub profile, opens in a new tab)commented

      Merging 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.

      Open the report in CodSpeed to investigate

      ⚡ 1 improved benchmark ❌ 1 (👁 1) regressed benchmark ✅ 189 untouched benchmarks ⏩ 3 skipped benchmarks1

      Performance Changes

      ModeBenchmarkBASEHEADEfficiency
      ⚡Simulationclient-control-flow navigation loop (react)99.3 ms90.7 ms+9.42%
      👁Memorymem server streaming-peak chunked (react)349.7 KB641.9 KB-45.52%

      Tip

      Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


      Comparing perf-react-router-reduce-component-nesting (fca385e) with main (1f0f20a) Open in CodSpeed

      Footnotes

      1. 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. ↩

Sign in to join this conversation.