Skip to content

perf: reuse prepared SSR request locations - #8441

Open
schiller-manuel wants to merge 1 commit into
mainfrom
codex/reuse-ssr-request-location
Open

schiller-manuel wants to merge 1 commit into
mainfrom
codex/reuse-ssr-request-location

Conversation

@schiller-manuel

@schiller-manuel schiller-manuel commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

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

Validation: affected unit, type, and lint checks passed, along with the server-routes Chromium tests. Regression coverage includes rewrites, encoded parameters, basepaths, mutable history, and route middleware.

The build-time shortcut for apps without server routes is a separate follow-up in #8444.

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

@coderabbitai

coderabbitai Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

Important

Review skipped

We couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting @coderabbitai full review.

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 b7600ee and 3df2769.

📒 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
Loading

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 | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning 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:… 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 and concisely describes the main change: reusing prepared SSR request locations.
Description check ✅ Passed The description follows the required template, explains the changes and motivation, documents validation, completes the checklist, and records the changeset release impact.
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.

@nx-cloud

nx-cloud Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 832a8a0

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ✅ Succeeded 11m 28s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 45s View ↗

☁️ Nx Cloud last updated this comment at 2026-09-16 21:27:38 UTC

@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

2 package(s) bumped directly, 21 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/router-core 1.171.31 → 1.171.32 Changeset
@tanstack/start-server-core 1.169.36 → 1.169.37 Changeset
@tanstack/react-router 1.170.37 → 1.170.38 Dependent
@tanstack/react-start 1.168.55 → 1.168.56 Dependent
@tanstack/react-start-client 1.168.35 → 1.168.36 Dependent
@tanstack/react-start-rsc 0.1.54 → 0.1.55 Dependent
@tanstack/react-start-server 1.167.42 → 1.167.43 Dependent
@tanstack/router-cli 1.167.37 → 1.167.38 Dependent
@tanstack/router-generator 1.167.37 → 1.167.38 Dependent
@tanstack/router-plugin 1.168.39 → 1.168.40 Dependent
@tanstack/router-vite-plugin 1.167.39 → 1.167.40 Dependent
@tanstack/solid-router 1.170.35 → 1.170.36 Dependent
@tanstack/solid-start 1.168.53 → 1.168.54 Dependent
@tanstack/solid-start-client 1.168.34 → 1.168.35 Dependent
@tanstack/solid-start-server 1.167.41 → 1.167.42 Dependent
@tanstack/start-client-core 1.170.31 → 1.170.32 Dependent
@tanstack/start-plugin-core 1.171.45 → 1.171.46 Dependent
@tanstack/start-static-server-functions 1.167.36 → 1.167.37 Dependent
@tanstack/start-storage-context 1.167.33 → 1.167.34 Dependent
@tanstack/vue-router 1.170.34 → 1.170.35 Dependent
@tanstack/vue-start 1.168.52 → 1.168.53 Dependent
@tanstack/vue-start-client 1.167.37 → 1.167.38 Dependent
@tanstack/vue-start-server 1.167.41 → 1.167.42 Dependent

@github-actions

github-actions Bot commented Sep 15, 2026

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: c412bab2133f
  • Measured at: 2026-09-16T21:28:43.109Z
  • Baseline source: history:ce10dcd4d9d3
  • 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.minimal 83.9 KiB
-2 B
83.7 KiB
+2 B
261.2 KiB
+24 B
73.2 KiB
+49 B
███▆▆▆▆▃▁▁▁▁
react-router.full 87.4 KiB
-12 B
87.3 KiB
-13 B
273.1 KiB
+16 B
76.3 KiB
+58 B
███▆▆▆▆▃▁▅▆▅
solid-router.minimal 33.5 KiB
-30 B
33.3 KiB
-34 B
95.9 KiB
+7 B
30.3 KiB
-12 B
▆▆▆▅▅▅▅▂▁▇█▇
solid-router.full 38.4 KiB
-36 B
38.2 KiB
-35 B
110.6 KiB
+7 B
34.6 KiB
+51 B
▄▄▄▄▄▄▄▂▁▇█▇
vue-router.minimal 49.4 KiB
+6 B
49.3 KiB
+5 B
136.7 KiB
+5 B
44.7 KiB
-3 B
███▆▆▆▆▃▁▁▁▁
vue-router.full 55.0 KiB
-30 B
54.9 KiB
-30 B
155.0 KiB
+5 B
49.7 KiB
-44 B
███▆▆▆▆▃▁▂▄▂
react-start.minimal 96.1 KiB
-32 B
96.0 KiB
-31 B
300.6 KiB
-2 B
83.4 KiB
-82 B
███████▇▇▁▁▁
react-start.query-integration 103.5 KiB
-26 B
103.4 KiB
-29 B
327.2 KiB
+10 B
89.8 KiB
-114 B
███████▇▆▁▁▁
react-start.deferred-hydration 96.8 KiB
-34 B
96.0 KiB
-32 B
301.9 KiB
-1 B
84.1 KiB
-53 B
███████▇▇▁▁▁
react-start.full 99.3 KiB
-30 B
99.1 KiB
-33 B
310.3 KiB
-15 B
86.2 KiB
-82 B
███████▇▇▁▁▁
react-start.rsbuild.minimal 99.6 KiB
-22 B
99.4 KiB
-22 B
311.4 KiB
+61 B
86.0 KiB
-100 B
███████▇▇▁▁▁
react-start.rsbuild.minimal-iife 100.0 KiB
-22 B
99.8 KiB
-22 B
312.3 KiB
+61 B
86.4 KiB
-107 B
███████▇▇▁▁▁
react-start.rsbuild.full 102.8 KiB
-25 B
102.7 KiB
-25 B
321.5 KiB
+61 B
88.7 KiB
-125 B
███████▇▆▁▁▁
solid-start.minimal 45.7 KiB
-49 B
45.6 KiB
-47 B
134.0 KiB
+3 B
40.7 KiB
-62 B
███████▇▇▁▁▁
solid-start.deferred-hydration 48.8 KiB
-27 B
45.6 KiB
-23 B
141.4 KiB
+3 B
43.5 KiB
-28 B
███████▇▇▁▁▁
solid-start.full 50.8 KiB
-30 B
50.7 KiB
-30 B
149.4 KiB
+10 B
45.1 KiB
-77 B
███████▇▆▁▁▁
vue-start.minimal 64.8 KiB
-13 B
64.7 KiB
-12 B
184.5 KiB
+5 B
57.9 KiB
-12 B
███████▇▇▁▁▁
vue-start.full 68.7 KiB
+3 B
68.6 KiB
+3 B
196.8 KiB
+5 B
61.1 KiB
-153 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.

@pkg-pr-new

pkg-pr-new Bot commented Sep 15, 2026

Copy link
Copy Markdown
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/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@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: 832a8a0

@codspeed

codspeed Bot commented Sep 15, 2026

Copy link
Copy Markdown

Merging this PR will regress 1 benchmark

⚠️ 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 regressed benchmark
✅ 187 untouched benchmarks
⏩ 3 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory mem server request-churn (react) 856.5 KB 1,112.6 KB -23.02%
Memory mem server streaming-peak chunked (react) 643.4 KB 351.8 KB +82.89%

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 (832a8a0) with main (de023a7)

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.

Comment thread packages/start-server-core/src/createStartHandler.ts
@schiller-manuel schiller-manuel changed the title perf: reuse prepared SSR request locations perf: avoid redundant SSR routing work Sep 15, 2026
@schiller-manuel
schiller-manuel force-pushed the codex/reuse-ssr-request-location branch from 3df2769 to b7600ee Compare September 15, 2026 23:04
@schiller-manuel schiller-manuel changed the title perf: avoid redundant SSR routing work perf: reuse prepared SSR request locations Sep 15, 2026
@schiller-manuel
schiller-manuel added this pull request to stack #8445 September 15, 2026 23:05
@schiller-manuel
schiller-manuel force-pushed the codex/reuse-ssr-request-location branch from b7600ee to 5727d34 Compare September 16, 2026 18:45
@schiller-manuel
schiller-manuel force-pushed the codex/reuse-ssr-request-location branch from 5727d34 to 832a8a0 Compare September 16, 2026 21:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants