Skip to content

Conversation

@schiller-manuel
Copy link
Contributor

@schiller-manuel schiller-manuel commented Dec 10, 2025

fixes #6028

Summary by CodeRabbit

  • Chores
    • Optimized server-side rendering dehydration to include only necessary route data during initial page load.
    • Improved route manifest building to more efficiently filter and structure route information.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 10, 2025

Walkthrough

This pull request refines SSR dehydration logic to selectively include route manifests based on active state. Active routes receive full manifests, inactive routes with assets receive asset-only entries, and routes without assets are omitted entirely. Additionally, Array.flatMap replaces Array.map in manifest route building to enable filtering empty entries.

Changes

Cohort / File(s) Change Summary
SSR manifest dehydration refinement
packages/router-core/src/ssr/ssr-server.ts
Modified manifest dehydration to build a set of active route IDs from router.state.matches, then filter routes to include full manifests for active routes, asset-only partial entries for inactive routes with assets, and omit routes without assets.
Route manifest building optimization
packages/start-server-core/src/router-manifest.ts
Replaced Array.map with Array.flatMap when building the routes object, adjusting return shape to [[k, result]] to enable filtering entries with no data via empty array returns.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20–25 minutes

  • Manifest structure understanding: Reviewers should verify the filtering logic correctly preserves asset arrays for inactive routes while omitting unnecessary data.
  • Asset preservation: Confirm that inactive routes with shared CSS/assets are properly retained in partial form to prevent unloading on navigation.
  • FlatMap behavior: Ensure the flatMap refactoring correctly skips empty entries and maintains the expected manifest shape.

Possibly related PRs

Suggested reviewers

  • birkskyum
  • lachlancollins

Poem

🐰 A manifest redux, oh what delight!
Active routes gleam in dehydrated light,
While shared assets rest, not lost to the way,
CSS stands firm through each nav array—
No more unload! The styles will stay. 🎨✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The PR title directly describes the main change: including assets in route manifest for all routes, which addresses the CSS unload issue.
Linked Issues check ✅ Passed The changes implement the fix for issue #6028 by ensuring assets (including CSS) are preserved in the route manifest during navigation between routes.
Out of Scope Changes check ✅ Passed All changes are scoped to fixing the manifest dehydration logic and route manifest building to preserve assets, directly addressing the linked issue.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-6028

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link

nx-cloud bot commented Dec 10, 2025

View your CI Pipeline Execution ↗ for commit 0d6870f

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

☁️ Nx Cloud last updated this comment at 2025-12-10 20:00:35 UTC

@pkg-pr-new
Copy link

pkg-pr-new bot commented Dec 10, 2025

More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@6058

@tanstack/directive-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@6058

@tanstack/eslint-plugin-router

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

@tanstack/history

npm i https://pkg.pr.new/TanStack/router/@tanstack/history@6058

@tanstack/nitro-v2-vite-plugin

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

@tanstack/react-router

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

@tanstack/react-router-devtools

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

@tanstack/react-router-ssr-query

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

@tanstack/react-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@6058

@tanstack/react-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@6058

@tanstack/react-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@6058

@tanstack/router-cli

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

@tanstack/router-core

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

@tanstack/router-devtools

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

@tanstack/router-devtools-core

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

@tanstack/router-generator

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

@tanstack/router-plugin

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

@tanstack/router-ssr-query-core

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

@tanstack/router-utils

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

@tanstack/router-vite-plugin

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

@tanstack/server-functions-plugin

npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@6058

@tanstack/solid-router

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

@tanstack/solid-router-devtools

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

@tanstack/solid-router-ssr-query

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

@tanstack/solid-start

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@6058

@tanstack/solid-start-client

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@6058

@tanstack/solid-start-server

npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@6058

@tanstack/start-client-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@6058

@tanstack/start-plugin-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@6058

@tanstack/start-server-core

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@6058

@tanstack/start-static-server-functions

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

@tanstack/start-storage-context

npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@6058

@tanstack/valibot-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@6058

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@6058

@tanstack/vue-router

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

@tanstack/vue-router-devtools

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

@tanstack/vue-router-ssr-query

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

@tanstack/zod-adapter

npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@6058

commit: 4fc4646

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
packages/router-core/src/ssr/ssr-server.ts (1)

159-160: Consider enhancing the comment to explain the rationale.

The comment accurately describes what the code does, but could be more explicit about why this behavior is necessary—specifically, to prevent shared CSS modules from being unloaded during navigation (fixes #6028).

Apply this diff to enhance the comment:

-      // For currently matched routes, send full manifest (preloads + assets)
-      // For all other routes, only send assets (no preloads as they are handled via dynamic imports)
+      // For currently matched routes, send full manifest (preloads + assets)
+      // For all other routes, only send assets (no preloads as they are handled via dynamic imports)
+      // This ensures shared assets (e.g., CSS modules) remain available during navigation (fixes #6028)
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 64dea9d and 4fc4646.

📒 Files selected for processing (2)
  • packages/router-core/src/ssr/ssr-server.ts (1 hunks)
  • packages/start-server-core/src/router-manifest.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Use TypeScript strict mode with extensive type safety for all code

Files:

  • packages/router-core/src/ssr/ssr-server.ts
  • packages/start-server-core/src/router-manifest.ts
**/*.{js,ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

Implement ESLint rules for router best practices using the ESLint plugin router

Files:

  • packages/router-core/src/ssr/ssr-server.ts
  • packages/start-server-core/src/router-manifest.ts
🧠 Learnings (2)
📚 Learning: 2025-10-08T08:11:47.088Z
Learnt from: nlynzaad
Repo: TanStack/router PR: 5402
File: packages/router-generator/tests/generator/no-formatted-route-tree/routeTree.nonnested.snapshot.ts:19-21
Timestamp: 2025-10-08T08:11:47.088Z
Learning: Test snapshot files in the router-generator tests directory (e.g., files matching the pattern `packages/router-generator/tests/generator/**/routeTree*.snapshot.ts` or `routeTree*.snapshot.js`) should not be modified or have issues flagged, as they are fixtures used to verify the generator's output and are intentionally preserved as-is.

Applied to files:

  • packages/start-server-core/src/router-manifest.ts
📚 Learning: 2025-11-02T16:16:24.898Z
Learnt from: nlynzaad
Repo: TanStack/router PR: 5732
File: packages/start-client-core/src/client/hydrateStart.ts:6-9
Timestamp: 2025-11-02T16:16:24.898Z
Learning: In packages/start-client-core/src/client/hydrateStart.ts, the `import/no-duplicates` ESLint disable is necessary for imports from `#tanstack-router-entry` and `#tanstack-start-entry` because both aliases resolve to the same placeholder file (`fake-start-entry.js`) in package.json during static analysis, even though they resolve to different files at runtime.

Applied to files:

  • packages/start-server-core/src/router-manifest.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Preview
  • GitHub Check: Test
🔇 Additional comments (3)
packages/start-server-core/src/router-manifest.ts (1)

39-39: LGTM! Clean refactor to enable filtering.

The change from map to flatMap combined with wrapping the return value in [[k, result]] enables proper filtering of routes without data while maintaining the correct structure for Object.fromEntries.

Also applies to: 56-56

packages/router-core/src/ssr/ssr-server.ts (2)

162-164: LGTM! Efficient active route detection.

Using a Set for O(1) lookup of active routes is the right approach. The variable naming is clear and the logic correctly handles all cases.


166-186: Excellent fix for the CSS unloading bug!

The conditional logic correctly addresses issue #6028 by ensuring:

  • Active routes receive full manifests (preloads + assets)
  • Inactive routes with assets receive asset-only manifests, preventing CSS modules from being unloaded during navigation
  • Routes without assets are filtered out to minimize payload size

The use of flatMap for conditional filtering is appropriate, and the improved parameter naming enhances readability.

@schiller-manuel schiller-manuel merged commit 9fe8c61 into main Dec 10, 2025
4 checks passed
@schiller-manuel schiller-manuel deleted the fix-6028 branch December 10, 2025 19:52
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.

CSS module gets unloaded on navigation, while still needed

2 participants