Skip to content

perf(router-core): cache static SSR manifest serialization in LRU - #8144

Draft
Sheraff wants to merge 2 commits into
mainfrom
perf/task3-ssr-manifest-cache
Draft

perf(router-core): cache static SSR manifest serialization in LRU#8144
Sheraff wants to merge 2 commits into
mainfrom
perf/task3-ssr-manifest-cache

Conversation

@Sheraff

@Sheraff Sheraff commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • dehydrate() ran serval/crossSerializeStream over the payload including the static route manifest (preparedManifest.routes) on every request, though it is byte-identical per matched-route set.
  • The serialized manifest fragment is now cached in a bounded LRU keyed by matched-route-ids (reusing lru-cache.ts) and emitted as its own $_TSR.router.manifest=… script immediately after the initial $_TSR.router= chunk (ScriptBuffer preserves order; client hydrate() reads it after all scripts execute). Per-request serialization covers only matches + dehydratedData.
  • Feasibility verified first: manifest data (build-time, JSON-safe) and match data never share object references, so splitting the seroval graph breaks nothing. Falls back to the old embedded path on any serialization failure. Prod-only, like the existing prepared-manifest LRU.

Performance

51 matched routes × 10 assets (~76KB payload), timing dehydrate + script take only:

path median
uncached baseline 0.55–0.59 ms
cache miss 0.53–0.57 ms (no added cost)
cache hit 0.24–0.25 ms (~2.3× faster) — p95 ~2.8ms → 0.3–0.5ms

Verification

  • New suite ssr-server-manifest-cache.test.ts (6 tests): cache-hit ≡ uncached hydration result, byte-identical repeat requests, emission ordering, request-assets merge over cache, LRU eviction correctness/boundedness.
  • test:unit ✅ (107 files / 1612 tests) · eslint ✅ · types ✅. Two pre-existing jsdom window.scrollTo unhandled errors reproduce identically on pristine main.

Risks

Dev-mode HMR manifest mutations aren't cached (intended); adapters baking per-request state into static-route bytes would be wrong (none exist today).

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

4 package(s) bumped directly, 19 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/react-router 1.170.31 → 1.170.32 Changeset
@tanstack/router-core 1.171.26 → 1.171.27 Changeset
@tanstack/solid-router 1.170.29 → 1.170.30 Changeset
@tanstack/vue-router 1.170.28 → 1.170.29 Changeset
@tanstack/react-start 1.168.48 → 1.168.49 Dependent
@tanstack/react-start-client 1.168.29 → 1.168.30 Dependent
@tanstack/react-start-rsc 0.1.47 → 0.1.48 Dependent
@tanstack/react-start-server 1.167.36 → 1.167.37 Dependent
@tanstack/router-cli 1.167.32 → 1.167.33 Dependent
@tanstack/router-generator 1.167.32 → 1.167.33 Dependent
@tanstack/router-plugin 1.168.34 → 1.168.35 Dependent
@tanstack/router-vite-plugin 1.167.34 → 1.167.35 Dependent
@tanstack/solid-start 1.168.46 → 1.168.47 Dependent
@tanstack/solid-start-client 1.168.28 → 1.168.29 Dependent
@tanstack/solid-start-server 1.167.35 → 1.167.36 Dependent
@tanstack/start-client-core 1.170.26 → 1.170.27 Dependent
@tanstack/start-plugin-core 1.171.38 → 1.171.39 Dependent
@tanstack/start-server-core 1.169.30 → 1.169.31 Dependent
@tanstack/start-static-server-functions 1.167.31 → 1.167.32 Dependent
@tanstack/start-storage-context 1.167.28 → 1.167.29 Dependent
@tanstack/vue-start 1.168.45 → 1.168.46 Dependent
@tanstack/vue-start-client 1.167.31 → 1.167.32 Dependent
@tanstack/vue-start-server 1.167.35 → 1.167.36 Dependent

@nx-cloud

nx-cloud Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit 89b6860

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

☁️ Nx Cloud last updated this comment at 2026-08-22 06:30:25 UTC

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 616770a8-2ae3-4399-99f3-9a7b4d593034

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

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.

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

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

@pkg-pr-new

pkg-pr-new Bot commented Aug 21, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@8144

@tanstack/eslint-plugin-router

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

@tanstack/eslint-plugin-start

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

@tanstack/history

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

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@8144

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

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

@tanstack/react-start-client

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

@tanstack/react-start-rsc

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

@tanstack/react-start-server

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

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

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

@tanstack/solid-start-client

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

@tanstack/solid-start-server

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

@tanstack/start-client-core

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

@tanstack/start-fn-stubs

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

@tanstack/start-plugin-core

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

@tanstack/start-server-core

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

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

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

@tanstack/valibot-adapter

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

@tanstack/virtual-file-routes

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

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/vue-start

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

@tanstack/vue-start-client

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

@tanstack/vue-start-server

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

@tanstack/zod-adapter

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

commit: 89b6860

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

At least one additional CI pipeline execution has run since the conclusion below was written and it may no longer be applicable.

Nx Cloud is proposing a fix for your failed CI:

We fixed a bug in createSerializedManifestFragment where the hasEntries flag was not updated after adding the inlineCssHrefs entry, and no comma guard existed before appending "routes":, producing malformed JS like {"scriptFormat":"esm""routes":...}. This invalid script caused a parse error on every hydrated page, breaking SSR/RSC hydration across all E2E suites. Adding hasEntries = true after the inlineCssHrefs block and a guarded comma before "routes": restores valid object literal output in all field combinations.

Note

We are verifying this fix by re-running a subset of the 20 failed tasks that were analyzed.

diff --git a/packages/router-core/src/ssr/ssr-server.ts b/packages/router-core/src/ssr/ssr-server.ts
index ee4cb579..5886823b 100644
--- a/packages/router-core/src/ssr/ssr-server.ts
+++ b/packages/router-core/src/ssr/ssr-server.ts
@@ -273,6 +273,10 @@ function createSerializedManifestFragment(
       head += ','
     }
     head += '"inlineStyle":{"attrs":{"suppressHydrationWarning":true}}'
+    hasEntries = true
+  }
+  if (hasEntries) {
+    head += ','
   }
   head += '"routes":'
 

Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally E8np-RSDj

Apply fix locally with your editor ↗   View interactive diff ↗



🎓 Learn more about Self-Healing CI on nx.dev

@codspeed-hq

codspeed-hq Bot commented Aug 21, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 3.03%

⚠️ 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

⚡ 13 improved benchmarks
❌ 12 regressed benchmarks
✅ 155 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory mem server error-paths unmatched (react) 544.1 KB 957.8 KB -43.19%
Memory mem server error-paths unmatched (solid) 559.8 KB 961.6 KB -41.78%
Memory mem server error-paths redirect (vue) 427.7 KB 733.2 KB -41.66%
Memory mem server error-paths not-found (solid) 557.9 KB 950.3 KB -41.29%
Memory mem server error-paths unmatched (vue) 577.6 KB 956.5 KB -39.61%
Memory mem server serialization-payload (solid) 4.4 MB 4.7 MB -5.3%
Memory mem client navigation-churn (solid) 592.5 KB 623.3 KB -4.93%
Memory mem server serialization-payload (vue) 4.5 MB 4.7 MB -4.75%
Simulation ssr assets linked-css control (react) 369.1 ms 383.1 ms -3.66%
Memory mem server request-churn (react) 662.6 KB 687.3 KB -3.6%
Memory mem client interrupted-navigations (vue) 368.7 KB 382.1 KB -3.5%
Simulation ssr server-fn not-found (vue) 290.4 ms 300.2 ms -3.28%
Memory mem server error-paths not-found (vue) 2,304.3 KB 475.9 KB ×4.8
Memory mem server aborted-requests (vue) 1.1 MB 1 MB +8.28%
Simulation ssr dehydrate plain control (vue) 602.8 ms 560.8 ms +7.49%
Simulation ssr server-fn during document ssr (vue) 674.5 ms 627.5 ms +7.48%
Simulation ssr dehydrate rich types (vue) 531.8 ms 500.3 ms +6.3%
Simulation ssr before-load chain (react) 217.7 ms 205.3 ms +6.04%
Memory mem server error-paths redirect (react) 318.9 KB 303.3 KB +5.15%
Simulation ssr not-found (solid) 238.4 ms 226.8 ms +5.09%
... ... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

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


Comparing perf/task3-ssr-manifest-cache (89b6860) with main (d83a896)

Open in CodSpeed

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.

1 participant