Skip to content
Source
Sign inSign up
TanStack/router

perf: reuse prepared SSR request locations #8441

Mergedschiller-manuel(GitHub profile, opens in a new tab)merged 1 commit intomain fromrefs/pull/8441/headmerged by schiller-manuel(GitHub profile, opens in a new tab)

🎯 Changes

Reuse the request location already prepared by the router during SSR. Server-route handling matches that parsed pathname instead of running the input rewrite again, while preserving encoded pathnames for handlers and middleware. SSR loading also skips the redundant location update; ordinary router loads retain their existing behavior.

Rebased on main after #7588.

Validation: router-core and start-server-core unit, type, and lint checks passed, along with the server-routes e2e (10 tests) and response-reconciliation e2e in all four modes. Regression coverage includes rewrites, encoded parameters, basepaths, mutable history, and route middleware.

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

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented
      Review Change StackReview Change Stack

      Important

      Review skipped

      The saved review history does not include the base for the last reviewed commit. This saved history cannot establish the base for an incremental review. Comment @coderabbitai full review to establish a new review baseline. No full review was started, and the last reviewed checkpoint was preserved.

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review

      No actionable comments were generated in the recent review. 🎉

      ℹ️ Recent review info
      ⚙️ Run configuration

      Configuration used: Path: .coderabbit.yaml

      Review profile: CHILL

      Plan: Advanced

      Run ID: 5879088e-e6c0-4f8d-9779-39a7c7f7c235

      📥 Commits

      Reviewing files that changed from the base of the PR and between b7600ee48d874488ef79be87a9301d3671224501 and 3df2769b5d94f19149e020e6e8a154c4e167cd7d.

      📒 Files selected for processing (19)
      • .changeset/polite-gifts-camp.md
      • packages/start-plugin-core/src/global.d.ts
      • packages/start-plugin-core/src/rsbuild/start-router-plugin.ts
      • packages/start-plugin-core/src/rsbuild/virtual-modules.ts
      • packages/start-plugin-core/src/start-manifest-plugin/manifestBuilder.ts
      • packages/start-plugin-core/src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts
      • packages/start-plugin-core/src/start-router-plugin/pruneServerOnlySubtrees.ts
      • packages/start-plugin-core/src/vite/dev-server-plugin/plugin.ts
      • packages/start-plugin-core/src/vite/start-manifest-plugin/plugin.ts
      • packages/start-plugin-core/src/vite/start-router-plugin/plugin.ts
      • packages/start-plugin-core/tests/routes-manifest-plugin.test.ts
      • packages/start-plugin-core/tests/rsbuild/virtual-modules.test.ts
      • packages/start-plugin-core/tests/start-manifest-plugin.test.ts
      • packages/start-plugin-core/tests/start-manifest-plugin/manifestBuilder.test.ts
      • packages/start-server-core/src/createStartHandler.ts
      • packages/start-server-core/src/tanstack-start.d.ts
      • packages/start-server-core/tests/createStartHandler.test.ts
      • packages/start-server-core/tests/fixtures/start-manifest.ts
      • packages/start-server-core/tsconfig.json

      Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.

      📝 Walkthrough

      Walkthrough

      SSR request handling now reuses the parsed request location. Server-route matching uses the prepared pathname, while handlers and middleware retain encoded pathnames. Build manifests now expose whether server routes exist.

      Changes

      SSR and server-route handling

      Layer / File(s)Summary
      Reuse prepared SSR locations
      packages/router-core/src/router.ts, packages/router-core/src/load-server.ts, packages/router-core/src/ssr/createRequestHandler.ts, packages/router-core/tests/server-history.test.ts
      SSR loads can skip location updates and reuse latestLocation. Tests cover rewrites, refreshes, search parsing, and loader data.
      Track server-route availability
      packages/start-plugin-core/src/start-router-plugin/*, packages/start-plugin-core/src/start-manifest-plugin/*, packages/start-plugin-core/src/vite/*, packages/start-plugin-core/src/rsbuild/*
      Route generation and manifest modules now carry hasServerRoutes. Build and development paths provide fallback values.
      Update server request flow
      packages/start-server-core/src/createStartHandler.ts, packages/start-server-core/src/tanstack-start.d.ts
      The handler reuses early-hints router instances, skips server-route matching when the manifest reports no server routes, avoids unconfigured middleware, and preserves encoded handler pathnames.
      Validate routing and manifest behavior
      packages/start-plugin-core/tests/*, packages/start-server-core/tests/*, .changeset/polite-gifts-camp.md
      Tests cover manifest detection, virtual modules, rewrites, origins, early hints, cancellation, and encoded parameters. The changeset declares patch releases.

      Priority: ⬇️ Low

      Estimated code review effort: 4 (Complex) | ~45 minutes

      Change: Refactor

      Sequence Diagram(s)

      sequenceDiagram
        participant Request
        participant createStartHandler
        participant Router
        participant ServerMiddleware
        Request->>createStartHandler: submit SSR request
        createStartHandler->>Router: prepare or reuse latestLocation
        createStartHandler->>ServerMiddleware: run configured middleware
        ServerMiddleware->>Router: getMatchedRoutes(location.pathname)
        createStartHandler->>Router: load(_skipLocationUpdate: true)
        Router-->>createStartHandler: return loaded route data

      Suggested reviewers: sheraff

      Merge Risk: ⚪ Minimal · up to 3df27

      The SSR request-location and server-route manifest changes retain their documented routing, rewrite, and fallback behavior. No concrete merge-blocking risk remains.

      Pre-merge checks · Passed 4 · Failed 1
      Failed Failed checks (1 warning)
      Check nameStatusExplanationResolution
      Docstring CoverageWarningDocstring coverage is 15.63% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 21 files. (2 skipped:…Write docstrings for the functions missing them to satisfy the coverage threshold.
      Passed Passed checks (4 passed)
      Check nameStatusExplanation
      Linked Issues checkPassedCheck skipped because no linked issues were found for this pull request.
      Out of Scope Changes checkPassedCheck skipped because no linked issues were found for this pull request.
      Title checkPassedThe title clearly and concisely describes the main change: reusing prepared SSR request locations.
      Description checkPassedThe description explains the changes and motivation, documents validation results, completes the required checklist, and includes the required changeset declaration.
      Full details: Docstring Coverage

      Explanation

      Docstring coverage is 15.63% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 32 functions across 21 files. (2 skipped: 2 unsupported.)

      ✨ Finishing Touches 💡 1
      📝 Generate docstrings 💡
      • Create stacked PR
      • Commit on current branch
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `codex/reuse-ssr-request-location`
      Comment `@coderabbitai help` to get the list of available commands.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core

    3. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-server-core

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

      View your CI Pipeline Execution ↗ for commit 28ba702d49ac7ec6f6f10df9c4bc338fd7a45cfb

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

      ☁️ Nx Cloud last updated this comment at 2026-10-12 23:18:33 UTC

    5. github-actions[bot](GitHub profile, opens in a new tab)commented

      🚀 Changeset Version Preview

      14 package(s) bumped directly, 9 bumped as dependents.

      🟨 Minor bumps

      PackageVersionReason
      @tanstack/react-start1.168.61 → 1.169.0Changeset
      @tanstack/solid-start1.168.58 → 1.169.0Changeset
      @tanstack/vue-start1.168.57 → 1.169.0Changeset

      🟩 Patch bumps

      PackageVersionReason
      @tanstack/react-start-rsc0.1.60 → 0.1.61Changeset
      @tanstack/react-start-server1.167.47 → 1.167.48Changeset
      @tanstack/router-core1.171.35 → 1.171.36Changeset
      @tanstack/router-generator1.167.41 → 1.167.42Changeset
      @tanstack/router-plugin1.168.43 → 1.168.44Changeset
      @tanstack/solid-start-server1.167.45 → 1.167.46Changeset
      @tanstack/start-client-core1.170.35 → 1.170.36Changeset
      @tanstack/start-plugin-core1.171.50 → 1.171.51Changeset
      @tanstack/start-server-core1.169.40 → 1.169.41Changeset
      @tanstack/start-storage-context1.167.37 → 1.167.38Changeset
      @tanstack/vue-start-server1.167.45 → 1.167.46Changeset
      @tanstack/react-router1.170.42 → 1.170.43Dependent
      @tanstack/react-start-client1.168.40 → 1.168.41Dependent
      @tanstack/router-cli1.167.41 → 1.167.42Dependent
      @tanstack/router-vite-plugin1.167.43 → 1.167.44Dependent
      @tanstack/solid-router1.170.39 → 1.170.40Dependent
      @tanstack/solid-start-client1.168.38 → 1.168.39Dependent
      @tanstack/start-static-server-functions1.167.40 → 1.167.41Dependent
      @tanstack/vue-router1.170.38 → 1.170.39Dependent
      @tanstack/vue-start-client1.167.41 → 1.167.42Dependent
    6. github-actions[bot](GitHub profile, opens in a new tab)commented

      Bundle Size Benchmarks

      This pull request does not affect bundle size in any measured scenario.

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

      @tanstack/eslint-plugin-router

      npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@8441

      @tanstack/eslint-plugin-start

      npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8441

      @tanstack/history

      npm i https://pkg.pr.new/@tanstack/history@8441

      @tanstack/react-router

      npm i https://pkg.pr.new/@tanstack/react-router@8441

      @tanstack/react-router-devtools

      npm i https://pkg.pr.new/@tanstack/react-router-devtools@8441

      @tanstack/react-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@8441

      @tanstack/react-start

      npm i https://pkg.pr.new/@tanstack/react-start@8441

      @tanstack/react-start-client

      npm i https://pkg.pr.new/@tanstack/react-start-client@8441

      @tanstack/react-start-rsc

      npm i https://pkg.pr.new/@tanstack/react-start-rsc@8441

      @tanstack/react-start-server

      npm i https://pkg.pr.new/@tanstack/react-start-server@8441

      @tanstack/router-cli

      npm i https://pkg.pr.new/@tanstack/router-cli@8441

      @tanstack/router-core

      npm i https://pkg.pr.new/@tanstack/router-core@8441

      @tanstack/router-devtools

      npm i https://pkg.pr.new/@tanstack/router-devtools@8441

      @tanstack/router-devtools-core

      npm i https://pkg.pr.new/@tanstack/router-devtools-core@8441

      @tanstack/router-generator

      npm i https://pkg.pr.new/@tanstack/router-generator@8441

      @tanstack/router-plugin

      npm i https://pkg.pr.new/@tanstack/router-plugin@8441

      @tanstack/router-ssr-query-core

      npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@8441

      @tanstack/router-utils

      npm i https://pkg.pr.new/@tanstack/router-utils@8441

      @tanstack/router-vite-plugin

      npm i https://pkg.pr.new/@tanstack/router-vite-plugin@8441

      @tanstack/solid-router

      npm i https://pkg.pr.new/@tanstack/solid-router@8441

      @tanstack/solid-router-devtools

      npm i https://pkg.pr.new/@tanstack/solid-router-devtools@8441

      @tanstack/solid-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8441

      @tanstack/solid-start

      npm i https://pkg.pr.new/@tanstack/solid-start@8441

      @tanstack/solid-start-client

      npm i https://pkg.pr.new/@tanstack/solid-start-client@8441

      @tanstack/solid-start-server

      npm i https://pkg.pr.new/@tanstack/solid-start-server@8441

      @tanstack/start-client-core

      npm i https://pkg.pr.new/@tanstack/start-client-core@8441

      @tanstack/start-fn-stubs

      npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8441

      @tanstack/start-plugin-core

      npm i https://pkg.pr.new/@tanstack/start-plugin-core@8441

      @tanstack/start-server-core

      npm i https://pkg.pr.new/@tanstack/start-server-core@8441

      @tanstack/start-static-server-functions

      npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8441

      @tanstack/start-storage-context

      npm i https://pkg.pr.new/@tanstack/start-storage-context@8441

      @tanstack/valibot-adapter

      npm i https://pkg.pr.new/@tanstack/valibot-adapter@8441

      @tanstack/virtual-file-routes

      npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8441

      @tanstack/vue-router

      npm i https://pkg.pr.new/@tanstack/vue-router@8441

      @tanstack/vue-router-devtools

      npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8441

      @tanstack/vue-router-ssr-query

      npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8441

      @tanstack/vue-start

      npm i https://pkg.pr.new/@tanstack/vue-start@8441

      @tanstack/vue-start-client

      npm i https://pkg.pr.new/@tanstack/vue-start-client@8441

      @tanstack/vue-start-server

      npm i https://pkg.pr.new/@tanstack/vue-start-server@8441

      @tanstack/zod-adapter

      npm i https://pkg.pr.new/@tanstack/zod-adapter@8441

      commit: 28ba702

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

      Merging this PR will degrade performance by 5.15%

      ⚡ 1 improved benchmark ❌ 2 regressed benchmarks ✅ 191 untouched benchmarks ⏩ 3 skipped benchmarks1

      Warning

      Please fix the performance issues or acknowledge them on CodSpeed.

      Performance Changes

      ModeBenchmarkBASEHEADEfficiency
      ❌Memorymem server error-paths redirect (solid)10.3 KB12.1 KB-14.48%
      ❌Memorymem server error-paths unmatched (vue)81.6 KB84.4 KB-3.34%
      ⚡Simulationssr rewrite localized (solid)204.6 ms198.3 ms+3.22%

      Tip

      Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


      Comparing codex/reuse-ssr-request-location (28ba702) with main (f243c61) 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. ↩

    9. Sheraff(GitHub profile, opens in a new tab) approved these changes

    10. github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-plugin-core

    11. 🦋 Changeset detected

      Latest commit: 28ba702d49ac7ec6f6f10df9c4bc338fd7a45cfb

      The changes in this PR will be included in the next version bump.

      This PR includes changesets to release 23 packages
      NameType
      @tanstack/router-corePatch
      @tanstack/start-server-corePatch
      @tanstack/react-routerPatch
      @tanstack/react-start-clientPatch
      @tanstack/react-start-rscPatch
      @tanstack/react-start-serverPatch
      @tanstack/router-generatorPatch
      @tanstack/router-pluginPatch
      @tanstack/solid-routerPatch
      @tanstack/solid-start-clientPatch
      @tanstack/solid-start-serverPatch
      @tanstack/start-client-corePatch
      @tanstack/start-plugin-corePatch
      @tanstack/start-storage-contextPatch
      @tanstack/vue-routerPatch
      @tanstack/vue-start-clientPatch
      @tanstack/vue-start-serverPatch
      @tanstack/react-startPatch
      @tanstack/solid-startPatch
      @tanstack/vue-startPatch
      @tanstack/router-cliPatch
      @tanstack/router-vite-pluginPatch
      @tanstack/start-static-server-functionsPatch

      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

Sign in to join this conversation.