fix: cleanup streamed values #5870
main fromrefs/pull/5870/head·merged by schiller-manuel(GitHub profile, opens in a new tab) Summary by CodeRabbit#
Refactor
- Improved server-side rendering script buffering and injection for more reliable timing and lifecycle handling.
- Client head rendering now includes buffered SSR scripts when available.
- Enhanced hydration/state tracking and post-hydration cleanup, plus a new global SSR marker.
Bug Fixes
- Manifest generation now excludes routes with no associated data.
Chores
- Removed an internal documentation comment (no runtime change).
- 1
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: react-router
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: solid-router
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: start-server-core
🤖 Nx Cloud AI Fix Eligible#
To disable these notifications, a workspace admin can disable them [in workspace settings.](https://cloud.nx.app/orgs/6412ca9d1c251d000efa21ba/workspaces/6442f7de8226a6291646a813/settings#selfHealingCISettings?utm_source=pull-request&utm_medium=comment)An automatically generated fix could have helped fix failing tasks for this run, but Self-healing CI is disabled for this workspace. Visit workspace settings to enable it and get automatic fixes in future runs.
View your CI Pipeline Execution ↗ for commit 27ee15b0398ab27f26dfb94e8e967010d6ee0b77
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...❌ Failed 7m 53s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 1m 24s View ↗
☁️ Nx Cloud last updated this comment at
2025-11-15 01:02:21UTCMore templates
- tanstack-router-react-example-authenticated-routes
- tanstack-router-react-example-authenticated-routes-firebase
- tanstack-router-react-example-basic
- tanstack-router-react-example-basic-default-search-params
- tanstack-router-react-example-basic-devtools-panel
- tanstack-router-react-example-basic-file-based
- tanstack-router-react-example-basic-non-nested-devtools
- tanstack-router-react-example-react-query
- tanstack-router-react-example-basic-react-query-file-based
- tanstack-router-react-example-basic-ssr-file-based
- tanstack-router-react-example-basic-ssr-streaming-file-based
- tanstack-router-react-example-basic-virtual-file-based
- tanstack-router-react-example-basic-virtual-inside-file-based
- tanstack-router-react-example-deferred-data
- tanstack-router-i18n-paraglide
- tanstack-router-react-example-kitchen-sink
- tanstack-router-react-example-kitchen-sink-file-based
- tanstack-router-react-example-kitchen-sink-react-query
- tanstack-router-react-example-kitchen-sink-react-query-file-based
- tanstack-router-react-example-large-file-based
- tanstack-router-react-example-location-masking
- tanstack-router-react-example-navigation-blocking
- tanstack-router-react-example-quickstart
- tanstack-router-react-example-quickstart-esbuild-file-based
- tanstack-router-react-example-quickstart-file-based
- tanstack-router-react-example-quickstart-rspack-file-based
- tanstack-router-react-example-quickstart-webpack-file-based
- router-monorepo-react-query
- router-mono-simple
- router-mono-simple-lazy
- tanstack-router-react-example-scroll-restoration
- tanstack-search-validator-adapters
- tanstack-start-example-bare
- tanstack-start-example-basic
- tanstack-start-example-basic-auth
- tanstack-start-example-basic-cloudflare
- tanstack-start-example-basic-react-query
- tanstack-start-example-basic-static
- tanstack-start-bun-hosting
- tanstack-start-example-clerk-basic
- tanstack-start-example-convex-trellaux
- tanstack-start-example-counter
- tanstack-start-i18n-paraglide
- tanstack-start-example-large
- tanstack-start-example-material-ui
- tanstack-start-streaming-data-from-server-functions
- tanstack-start-example-supabase-basic
- tanstack-start-tailwind-v4
- tanstack-start-example-trellaux
- tanstack-start-example-workos
- tanstack-router-react-example-view-transitions
- tanstack-router-react-example-with-framer-motion
- tanstack-router-react-example-with-trpc
- tanstack-router-react-example-with-trpc-react-query
- tanstack-router-solid-example-authenticated-routes
- tanstack-router-solid-example-authenticated-routes-firebase
- tanstack-router-solid-example-basic
- tanstack-router-solid-example-basic-default-search-params
- tanstack-router-solid-example-basic-devtools-panel
- tanstack-router-solid-example-basic-file-based
- tanstack-router-solid-example-basic-non-nested-devtools
- tanstack-router-solid-example-basic-solid-query
- tanstack-router-solid-example-basic-solid-query-file-based
- tanstack-router-solid-example-basic-ssr-file-based
- tanstack-router-solid-example-basic-ssr-streaming-file-based
- tanstack-router-solid-example-basic-virtual-file-based
- tanstack-router-solid-example-basic-virtual-inside-file-based
- tanstack-router-solid-example-deferred-data
- tanstack-router-solid-i18n-paraglide
- tanstack-router-solid-example-kitchen-sink
- tanstack-router-solid-example-kitchen-sink-file-based
- tanstack-router-solid-example-kitchen-sink-solid-query
- tanstack-router-solid-example-kitchen-sink-solid-query-file-based
- tanstack-router-solid-example-large-file-based
- tanstack-router-solid-example-location-masking
- tanstack-router-solid-example-navigation-blocking
- tanstack-router-solid-example-quickstart
- tanstack-router-solid-example-quickstart-esbuild-file-based
- tanstack-router-solid-example-quickstart-file-based
- tanstack-router-solid-example-quickstart-rspack-file-based
- tanstack-router-solid-example-quickstart-webpack-file-based
- router-solid-mono-simple
- router-solid-mono-simple-lazy
- router-solid-monorepo-solid-query
- tanstack-router-solid-example-scroll-restoration
- tanstack-solid-router-search-validator-adapters
- tanstack-solid-start-example-basic
- tanstack-solid-start-example-basic-auth
- tanstack-solid-start-example-basic-cloudflare
- tanstack-solid-start-example-basic-netlify
- tanstack-solid-start-example-basic-nitro
- tanstack-start-example-basic-solid-query
- tanstack-solid-start-example-basic-static
- tanstack-solid-start-bun-hosting
- tanstack-solid-start-example-convex-better-auth
- tanstack-solid-start-example-counter
- tanstack-solid-start-i18n-paraglide
- tanstack-solid-start-example-large
- tanstack-solid-start-streaming-data-from-server-functions
- tanstack-solid-start-example-supabase-basic
- tanstack-solid-start-tailwind-v4
- tanstack-router-solid-example-view-transitions
- tanstack-router-solid-example-with-framer-motion
- tanstack-router-solid-example-with-trpc
@tanstack/arktype-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/arktype-adapter@5870@tanstack/directive-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/directive-functions-plugin@5870@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/eslint-plugin-router@5870@tanstack/history
npm i https://pkg.pr.new/TanStack/router/@tanstack/history@5870@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/nitro-v2-vite-plugin@5870@tanstack/react-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router@5870@tanstack/react-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-devtools@5870@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-router-ssr-query@5870@tanstack/react-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start@5870@tanstack/react-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-client@5870@tanstack/react-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/react-start-server@5870@tanstack/router-cli
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-cli@5870@tanstack/router-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-core@5870@tanstack/router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools@5870@tanstack/router-devtools-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-devtools-core@5870@tanstack/router-generator
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-generator@5870@tanstack/router-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-plugin@5870@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-ssr-query-core@5870@tanstack/router-utils
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-utils@5870@tanstack/router-vite-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/router-vite-plugin@5870@tanstack/server-functions-plugin
npm i https://pkg.pr.new/TanStack/router/@tanstack/server-functions-plugin@5870@tanstack/solid-router
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router@5870@tanstack/solid-router-devtools
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-devtools@5870@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-router-ssr-query@5870@tanstack/solid-start
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start@5870@tanstack/solid-start-client
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-client@5870@tanstack/solid-start-server
npm i https://pkg.pr.new/TanStack/router/@tanstack/solid-start-server@5870@tanstack/start-client-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-client-core@5870@tanstack/start-plugin-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-plugin-core@5870@tanstack/start-server-core
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-server-core@5870@tanstack/start-static-server-functions
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-static-server-functions@5870@tanstack/start-storage-context
npm i https://pkg.pr.new/TanStack/router/@tanstack/start-storage-context@5870@tanstack/valibot-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/valibot-adapter@5870@tanstack/virtual-file-routes
npm i https://pkg.pr.new/TanStack/router/@tanstack/virtual-file-routes@5870@tanstack/zod-adapter
npm i https://pkg.pr.new/TanStack/router/@tanstack/zod-adapter@5870commit:
a272ef0Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 559856b7bfa2d85c2f3909de15c0e5c7063bd6ae and a272ef03d94d0370fde0029178bb984e7b88c8e0.
📒 Files selected for processing (9)
packages/react-router/src/HeadContent.tsx(2 hunks)packages/react-router/src/ScriptOnce.tsx(0 hunks)packages/router-core/src/router.ts(1 hunks)packages/router-core/src/ssr/constants.ts(1 hunks)packages/router-core/src/ssr/ssr-client.ts(3 hunks)packages/router-core/src/ssr/ssr-server.ts(7 hunks)packages/router-core/src/ssr/tsrScript.ts(1 hunks)packages/solid-router/src/HeadContent.tsx(1 hunks)packages/start-server-core/src/router-manifest.ts(1 hunks)
💤 Files with no reviewable changes (1)
- packages/react-router/src/ScriptOnce.tsx
🧰 Additional context used
🧠 Learnings (4)
📚 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/router-core/src/ssr/ssr-client.tspackages/start-server-core/src/router-manifest.ts
📚 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-10-01T18:31:35.420Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: e2e/react-start/custom-basepath/src/routeTree.gen.ts:58-61 Timestamp: 2025-10-01T18:31:35.420Z Learning: Do not review files named `routeTree.gen.ts` in TanStack Router repositories, as these are autogenerated files that should not be manually modified.Applied to files:
packages/start-server-core/src/router-manifest.ts
📚 Learning: 2025-10-01T18:30:26.591Z
Learnt from: schiller-manuel Repo: TanStack/router PR: 5330 File: packages/router-core/src/router.ts:2231-2245 Timestamp: 2025-10-01T18:30:26.591Z Learning: In `packages/router-core/src/router.ts`, the `resolveRedirect` method intentionally strips the router's origin from redirect URLs when they match (e.g., `https://foo.com/bar` → `/bar` for same-origin redirects) while preserving the full URL for cross-origin redirects. This logic should not be removed or simplified to use `location.publicHref` directly.Applied to files:
packages/start-server-core/src/router-manifest.ts
🧬 Code graph analysis (3)
packages/react-router/src/HeadContent.tsx (1)
packages/react-router/src/useRouterState.tsx (1)
useRouterState(48-76)
packages/router-core/src/ssr/ssr-client.ts (1)
packages/router-core/src/ssr/constants.ts (1)
GLOBAL_TSR(1-1)
packages/router-core/src/ssr/ssr-server.ts (3)
packages/router-core/src/router.ts (1)
AnyRouter(768-768)
packages/router-core/src/ssr/constants.ts (1)
GLOBAL_TSR(1-1)
packages/router-core/src/ssr/tsrScript.ts (1)
p(11-13)
⏰ 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: Test
- GitHub Check: Preview
🔇 Additional comments (1)
packages/start-server-core/src/router-manifest.ts (1)
46-57: LGTM! Clean filtering of routes without data.The
hasDataflag and conditional return pattern correctly filter out routes that have neither preloads nor assets. The explicit length checks handle both undefined and empty array cases properly. Since the root route is guaranteed to have at least one asset (the client entry script added at line 28), it won't be inadvertently filtered.packages/router-core/src/ssr/constants.ts line 2Outdated@@ -1 +1,2 @@11 export const GLOBAL_TSR = '$_TSR'2+export declare const GLOBAL_SEROVAL = '$R'⚠️ Potential issue | 🔴 Critical
Fix the invalid constant declaration
Line 2 uses
export declare const … = …, which is illegal in a.tsmodule (ambient declarations cannot have initializers). This will make TypeScript fail to compile. Please switch to a normal constant export.-export declare const GLOBAL_SEROVAL = '$R' +export const GLOBAL_SEROVAL = '$R'📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
export const GLOBAL_SEROVAL = '$R'🤖 Prompt for AI Agents
In packages/router-core/src/ssr/constants.ts around line 2, the file currently uses an ambient declaration with an initializer ("export declare const ... = ...") which is illegal in a TS module; change it to a normal exported constant by removing the "declare" keyword (e.g., use "export const GLOBAL_SEROVAL = '$R'") so the initializer is allowed and the module compiles.packages/router-core/src/ssr/ssr-client.ts lines 9 to 15@@ -6,9 +6,10 @@66 import type { Manifest } from '../manifest'77 import type { RouteContextOptions } from '../route'88 import type { AnySerializationAdapter } from './serializer/transformer'9-import type { GLOBAL_TSR } from './constants'9+import type { GLOBAL_SEROVAL, GLOBAL_TSR } from './constants'10101111 declare global {1212 interface Window {1313 [GLOBAL_TSR]?: TsrSsrGlobal14+ [GLOBAL_SEROVAL]?: any1415 }⚠️ Potential issue | 🔴 Critical
Import the constants as runtime values
GLOBAL_TSR(and the newGLOBAL_SEROVAL) are exported as runtime constants, soimport type { … }cannot resolve them—TypeScript reports “has no exported member” and compilation stops. Bring them in as normal value imports instead.-import type { GLOBAL_SEROVAL, GLOBAL_TSR } from './constants' +import { GLOBAL_SEROVAL, GLOBAL_TSR } from './constants'📝 Committable suggestion
‼️ IMPORTANT Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
import { GLOBAL_SEROVAL, GLOBAL_TSR } from './constants' declare global { interface Window { [GLOBAL_TSR]?: TsrSsrGlobal [GLOBAL_SEROVAL]?: any }🤖 Prompt for AI Agents
In packages/router-core/src/ssr/ssr-client.ts around lines 9 to 15, the file imports GLOBAL_TSR and GLOBAL_SEROVAL using "import type" but those are runtime-exported constants and must be imported as actual values; change the import to a normal value import (remove "type") so the constants are available at runtime, keep any type-only imports as "import type" if needed, and update any references to use the imported runtime values; rebuild to ensure TypeScript no longer reports the missing exported member error.
Sign in to join this conversation.
Caution
Review failed#
The pull request is closed.
Walkthrough#
Introduces server-side SSR script buffering (ScriptBuffer) and exposes router.serverSsr.takeBufferedScripts(); integrates buffered scripts into React and Solid HeadContent with nonce/class; extends global SSR typings and client hydration flow (hydrated/streamEnd) with cleanup; refines route manifest to omit routes without preload/assets.
Changes#
packages/router-core/src/ssr/ssr-server.tsScriptBufferto enqueue/buffer SSR scripts, barrier control, replaced immediate injection with buffering, addedtakeBufferedScripts()API, and flush on render-finish.packages/router-core/src/router.tstakeBufferedScripts(): string | undefinedtoServerSsrinterface.packages/router-core/src/ssr/constants.ts,packages/router-core/src/ssr/ssr-client.tsGLOBAL_SEROVALconstant; extended globalTsrSsrGlobalwithhydrated?: booleanandstreamEnd?: boolean; set hydrated and invoke cleanup post-hydration.packages/router-core/src/ssr/tsrScript.tsself.$_TSRandself.$R['tsr']when bothhydratedandstreamEndare true (in addition to existing element cleanup).packages/react-router/src/HeadContent.tsx,packages/solid-router/src/HeadContent.tsxrouter.serverSsr.takeBufferedScripts()when available; if present, create a serverHeadScript tag (script, nonce, class$tsr) and include it in deduped head tags.packages/react-router/src/ScriptOnce.tsxpackages/start-server-core/src/router-manifest.tsSequence Diagram#
Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~45 minutes
Areas needing extra attention:
packages/router-core/src/ssr/ssr-server.ts— ScriptBuffer concurrency/barrier, enqueue vs immediate injection, interaction with takeBufferedScripts and liftBarrier.packages/router-core/src/ssr/ssr-client.ts&tsrScript.ts— hydration/streamEnd flag timing and cleanup correctness.packages/react-router/src/HeadContent.tsx&packages/solid-router/src/HeadContent.tsx— nonce propagation, className, and deduplication interaction.packages/start-server-core/src/router-manifest.ts— manifest shape changes and potential consumers relying on previous spread.Possibly related PRs#
Suggested reviewers#
Poem#
Pre-merge checks and finishing touches#
❌ Failed checks (1 warning)
@coderabbitai generate docstringsto improve docstring coverage.✅ Passed checks (2 passed)
📜 Recent review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between a272ef03d94d0370fde0029178bb984e7b88c8e0 and 27ee15b0398ab27f26dfb94e8e967010d6ee0b77.
📒 Files selected for processing (1)
packages/router-core/src/ssr/constants.ts(1 hunks)Comment `@coderabbitai help` to get the list of available commands and usage tips.