fix: fix streaming #7497
main fromrefs/pull/7497/head·merged by schiller-manuel(GitHub profile, opens in a new tab) fixes #7402
Summary by CodeRabbit#
Bug Fixes
- Improved SSR streaming reliability for request aborts/cancellations across React, Vue, and Solid
- Fixed HTML/script injection ordering and buffering to prevent mid-tag injection
- Hardened query-stream teardown, cache cleanup, and in-flight query handling
- Addressed backpressure issues to bound memory during streaming
New Features
- Added SSR fast-path streaming mode for lower-latency passthrough
- Exposed richer SSR lifecycle hooks for finer cleanup/control
Tests
- Added extensive SSR streaming, cleanup, backpressure, and e2e query-stream tests
- 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
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: router-ssr-query-core
github-actions[bot](GitHub profile, opens in a new tab) added labelspackage: vue-router
View your CI Pipeline Execution ↗ for commit ef37315ca76a297ff3d46b129f50de0b197e2d37
Command Status Duration Result nx affected --targets=test:eslint,test:unit,tes...✅ Succeeded 8m 46s View ↗ nx run-many --target=build --exclude=examples/*...✅ Succeeded 2m 2s View ↗
☁️ Nx Cloud last updated this comment at
2026-05-29 00:26:45UTC🚀 Changeset Version Preview#
6 package(s) bumped directly, 21 bumped as dependents.
🟩 Patch bumps#
Package Version Reason @tanstack/react-router1.170.8 → 1.170.9 Changeset @tanstack/router-core1.171.6 → 1.171.7 Changeset @tanstack/router-ssr-query-core1.169.0 → 1.169.1 Changeset @tanstack/solid-router1.170.8 → 1.170.9 Changeset @tanstack/start-server-core1.169.5 → 1.169.6 Changeset @tanstack/vue-router1.170.8 → 1.170.9 Changeset @tanstack/react-router-ssr-query1.167.0 → 1.167.1 Dependent @tanstack/react-start1.168.15 → 1.168.16 Dependent @tanstack/react-start-client1.168.5 → 1.168.6 Dependent @tanstack/react-start-rsc0.1.14 → 0.1.15 Dependent @tanstack/react-start-server1.167.10 → 1.167.11 Dependent @tanstack/router-cli1.167.10 → 1.167.11 Dependent @tanstack/router-generator1.167.10 → 1.167.11 Dependent @tanstack/router-plugin1.168.11 → 1.168.12 Dependent @tanstack/router-vite-plugin1.167.11 → 1.167.12 Dependent @tanstack/solid-router-ssr-query1.167.0 → 1.167.1 Dependent @tanstack/solid-start1.168.15 → 1.168.16 Dependent @tanstack/solid-start-client1.168.5 → 1.168.6 Dependent @tanstack/solid-start-server1.167.10 → 1.167.11 Dependent @tanstack/start-client-core1.170.4 → 1.170.5 Dependent @tanstack/start-plugin-core1.171.7 → 1.171.8 Dependent @tanstack/start-static-server-functions1.167.9 → 1.167.10 Dependent @tanstack/start-storage-context1.167.8 → 1.167.9 Dependent @tanstack/vue-router-ssr-query1.167.0 → 1.167.1 Dependent @tanstack/vue-start1.168.14 → 1.168.15 Dependent @tanstack/vue-start-client1.167.9 → 1.167.10 Dependent @tanstack/vue-start-server1.167.10 → 1.167.11 Dependent Bundle Size Benchmarks#
- Commit:
aa867fc2c431 - Measured at:
2026-05-29T00:19:04.078Z - Baseline source:
history:c79b3964121c - Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend react-router.minimal87.30 KiB 0 B (0.00%) 87.16 KiB 274.03 KiB 75.92 KiB ▁▁▁████████ react-router.full90.75 KiB 0 B (0.00%) 90.61 KiB 285.39 KiB 78.80 KiB █▁▁▂▂▂▂▂▂▂▂ solid-router.minimal35.53 KiB 0 B (0.00%) 35.41 KiB 106.33 KiB 32.01 KiB ▁▁▁████████ solid-router.full40.23 KiB 0 B (0.00%) 40.11 KiB 120.52 KiB 36.19 KiB █▂▂▁▁▁▁▁▁▁▁ vue-router.minimal53.02 KiB 0 B (0.00%) 52.89 KiB 150.35 KiB 47.56 KiB ███▁▁▁▁▁▁▁▁ vue-router.full58.65 KiB 0 B (0.00%) 58.52 KiB 168.08 KiB 52.55 KiB ▁██▅▅▅▅▅▅▅▅ react-start.minimal101.93 KiB 0 B (0.00%) 101.79 KiB 322.35 KiB 88.25 KiB █▁▁▁▁▁▁▁▁▁▁ react-start.deferred-hydration102.66 KiB 0 B (0.00%) 101.81 KiB 323.72 KiB 88.82 KiB █▆▆▁▁▁▁▁▁▁▁ react-start.full105.31 KiB 0 B (0.00%) 105.17 KiB 332.66 KiB 91.06 KiB █▁▁▁▁▁▁▁▁▁▁ react-start.rsbuild.minimal99.61 KiB 0 B (0.00%) 99.44 KiB 316.79 KiB 85.73 KiB █▁▁▁▁▂▂▂▂▂▂ react-start.rsbuild.full102.88 KiB 0 B (0.00%) 102.71 KiB 327.18 KiB 88.52 KiB █▁▁▁▁▁▁▁▁▁▁ solid-start.minimal49.63 KiB 0 B (0.00%) 49.50 KiB 152.40 KiB 43.84 KiB █▁▁▁▁▁▁▁▁▁▁ solid-start.deferred-hydration52.89 KiB 0 B (0.00%) 49.55 KiB 160.44 KiB 46.71 KiB ███▁▁▁▁▁▁▁▁ solid-start.full55.41 KiB 0 B (0.00%) 55.29 KiB 169.33 KiB 48.81 KiB █▁▁▁▁▁▁▁▁▁▁ 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.
- Commit:
More 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-router-react-example-basic-authjs
- 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-example-rscs
- 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-vue-example-basic-jsx
- tanstack-router-vue-example-basic-file-based-jsx
- tanstack-router-vue-example-basic-file-based-sfc
- 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
- @tanstack/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-authjs
- 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/arktype-adapter@7497@tanstack/eslint-plugin-router
npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@7497@tanstack/eslint-plugin-start
npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@7497@tanstack/history
npm i https://pkg.pr.new/@tanstack/history@7497@tanstack/nitro-v2-vite-plugin
npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@7497@tanstack/react-router
npm i https://pkg.pr.new/@tanstack/react-router@7497@tanstack/react-router-devtools
npm i https://pkg.pr.new/@tanstack/react-router-devtools@7497@tanstack/react-router-ssr-query
npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@7497@tanstack/react-start
npm i https://pkg.pr.new/@tanstack/react-start@7497@tanstack/react-start-client
npm i https://pkg.pr.new/@tanstack/react-start-client@7497@tanstack/react-start-rsc
npm i https://pkg.pr.new/@tanstack/react-start-rsc@7497@tanstack/react-start-server
npm i https://pkg.pr.new/@tanstack/react-start-server@7497@tanstack/router-cli
npm i https://pkg.pr.new/@tanstack/router-cli@7497@tanstack/router-core
npm i https://pkg.pr.new/@tanstack/router-core@7497@tanstack/router-devtools
npm i https://pkg.pr.new/@tanstack/router-devtools@7497@tanstack/router-devtools-core
npm i https://pkg.pr.new/@tanstack/router-devtools-core@7497@tanstack/router-generator
npm i https://pkg.pr.new/@tanstack/router-generator@7497@tanstack/router-plugin
npm i https://pkg.pr.new/@tanstack/router-plugin@7497@tanstack/router-ssr-query-core
npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@7497@tanstack/router-utils
npm i https://pkg.pr.new/@tanstack/router-utils@7497@tanstack/router-vite-plugin
npm i https://pkg.pr.new/@tanstack/router-vite-plugin@7497@tanstack/solid-router
npm i https://pkg.pr.new/@tanstack/solid-router@7497@tanstack/solid-router-devtools
npm i https://pkg.pr.new/@tanstack/solid-router-devtools@7497@tanstack/solid-router-ssr-query
npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@7497@tanstack/solid-start
npm i https://pkg.pr.new/@tanstack/solid-start@7497@tanstack/solid-start-client
npm i https://pkg.pr.new/@tanstack/solid-start-client@7497@tanstack/solid-start-server
npm i https://pkg.pr.new/@tanstack/solid-start-server@7497@tanstack/start-client-core
npm i https://pkg.pr.new/@tanstack/start-client-core@7497@tanstack/start-fn-stubs
npm i https://pkg.pr.new/@tanstack/start-fn-stubs@7497@tanstack/start-plugin-core
npm i https://pkg.pr.new/@tanstack/start-plugin-core@7497@tanstack/start-server-core
npm i https://pkg.pr.new/@tanstack/start-server-core@7497@tanstack/start-static-server-functions
npm i https://pkg.pr.new/@tanstack/start-static-server-functions@7497@tanstack/start-storage-context
npm i https://pkg.pr.new/@tanstack/start-storage-context@7497@tanstack/valibot-adapter
npm i https://pkg.pr.new/@tanstack/valibot-adapter@7497@tanstack/virtual-file-routes
npm i https://pkg.pr.new/@tanstack/virtual-file-routes@7497@tanstack/vue-router
npm i https://pkg.pr.new/@tanstack/vue-router@7497@tanstack/vue-router-devtools
npm i https://pkg.pr.new/@tanstack/vue-router-devtools@7497@tanstack/vue-router-ssr-query
npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@7497@tanstack/vue-start
npm i https://pkg.pr.new/@tanstack/vue-start@7497@tanstack/vue-start-client
npm i https://pkg.pr.new/@tanstack/vue-start-client@7497@tanstack/vue-start-server
npm i https://pkg.pr.new/@tanstack/vue-start-server@7497@tanstack/zod-adapter
npm i https://pkg.pr.new/@tanstack/zod-adapter@7497commit:
0c0a6ccActionable comments posted: 5
🧹 Nitpick comments (7)
packages/vue-router/tests/renderRouterToStream.test.tsx (1)
40-52: 💤 Low valueConsider adding
await router.serverSsr!.dehydrate()inbuildRouter.The bot test (line 70) manually calls
dehydrate(), butbuildRouterdoesn't include it. For consistency with the pattern across all framework tests, consider including it in the helper or documenting why it's only needed for the bot test.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/vue-router/tests/renderRouterToStream.test.tsx` around lines 40 - 52, The helper buildRouter sets up server SSR utils but does not call the server-side dehydrate step, causing inconsistent setup vs tests that call router.serverSsr!.dehydrate() manually; update buildRouter to await router.serverSsr!.dehydrate() after attachRouterServerSsrUtils({ router, manifest: undefined }) and before returning the router (or document in a comment why a specific test should call dehydrate itself), so tests can rely on buildRouter returning a fully dehydrated server router.packages/react-router/tests/renderRouterToStream.test.tsx (1)
23-34: 💤 Low valueConsider adding
await router.serverSsr!.dehydrate()for completeness.The
buildRouterhelper loads the router but doesn't calldehydrate(). While some tests (like line 32 in the setup throw test'sbuildRoutercall) do call it separately, other tests rely onbuildRouterdirectly. This inconsistency could lead to flaky behavior if future tests expect dehydration to have occurred.Looking at the Solid/Vue test files, they also have this pattern inconsistently applied.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/react-router/tests/renderRouterToStream.test.tsx` around lines 23 - 34, The helper buildRouter does not consistently dehydrate the server SSR state; update buildRouter to call and await router.serverSsr!.dehydrate() after attachRouterServerSsrUtils({ router, manifest: undefined }) and after await router.load(), so that the router is always dehydrated before return; locate the function buildRouter and add the await router.serverSsr!.dehydrate() invocation (using the existing router.serverSsr property) prior to returning the router.packages/solid-router/tests/renderRouterToStream.test.tsx (1)
34-46: 💤 Low valueConsider adding
await router.serverSsr!.dehydrate()for test consistency.Similar to the React tests,
buildRouterdoesn't calldehydrate(). While this may work for the current tests, adding it would match the pattern in other test files and ensure the router is in the expected SSR state.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/solid-router/tests/renderRouterToStream.test.tsx` around lines 34 - 46, Add a call to dehydrate the server SSR state in buildRouter: after attaching SSR utils with attachRouterServerSsrUtils({ router, manifest: undefined }) and finishing router.load(), invoke await router.serverSsr!.dehydrate() so the router is put into the same SSR-dehydrated state used by other tests; reference the buildRouter function and the router.serverSsr!.dehydrate() method when making this change.packages/start-server-core/src/createStartHandler.ts (1)
214-217: 🏗️ Heavy liftReplace
TODO/anymiddleware contracts with concrete types.executeMiddlewarenow sits on a critical SSR cleanup path, but still accepts/returnsTODO(any) in core control flow. Tightening these types would prevent accidental invalid response/context shapes from bypassing cleanup logic.As per coding guidelines
**/*.{ts,tsx}: Use TypeScript strict mode with extensive type safety.Also applies to: 524-532, 648-656
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/start-server-core/src/createStartHandler.ts` around lines 214 - 217, The executeMiddleware signature (and analogous spots at the other occurrences) uses TODO/any for middleware and ctx; replace these with concrete, strict types: define a RequestContext (or reuse existing context type used across the SSR pipeline) for ctx, a Middleware type like (ctx: RequestContext) => Promise<void | HandlerCallbackResult | Response> (or synchronous equivalents), and ensure executeMiddleware returns Promise<{ ctx: RequestContext; response: HandlerCallbackResult }>; update any intermediate helper types (e.g., HandlerCallbackResult) so their shape is explicit (status, headers, body, etc.), and propagate these concrete types into the other two locations referenced so the cleanup path enforces correct shapes rather than any/ TODO.packages/start-server-core/tests/createStartHandler.test.ts (1)
72-82: ⚡ Quick winReduce repeated
as anycasts in new SSR test helpers.Please introduce small helper types (typed router/typed SSR response) so ownership tests keep compile-time guarantees without pervasive
anycasts.As per coding guidelines
**/*.{ts,tsx}: Use TypeScript strict mode with extensive type safety.Also applies to: 106-107, 129-130, 189-190, 217-218, 251-252, 277-278, 304-305
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/start-server-core/tests/createStartHandler.test.ts` around lines 72 - 82, Replace the repeated `as any` casts by introducing small test-only types and helper factories: add a TypedTestRouter (or TestRouter) interface representing the minimal router shape used by attachRouterServerSsrUtils and createSsrStreamResponse, and a helper function (e.g., makeTestRouter()) that returns a strongly-typed instance; likewise add a TypedSsrResponse or makeTestSsrResponse(stream) helper that returns Response with the proper typed serverSsr attached. Update calls to attachRouterServerSsrUtils({ router: router as any, ... }) and createSsrStreamResponse(router as any, ...) to use the new test helpers or typed variables (router: TestRouter) so the code at symbols attachRouterServerSsrUtils and createSsrStreamResponse no longer needs `as any`; apply the same pattern to the other occurrences listed (lines ~106-107, 129-130, 189-190, 217-218, 251-252, 277-278, 304-305).packages/router-core/tests/transformStreamWithRouter.test.ts (1)
185-199: 🏗️ Heavy liftConsolidate typed test fakes to remove repeated
as anycasts.The suite is strong, but repeated
anycasts weaken strict-mode guarantees. A small typed test harness (typed fake router + typed transform wrappers) would keep the same coverage without type escapes.As per coding guidelines
**/*.{ts,tsx}: Use TypeScript strict mode with extensive type safety.Also applies to: 223-226, 946-950
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/router-core/tests/transformStreamWithRouter.test.ts` around lines 185 - 199, Tests repeatedly use `as any` casts (weakening strict-mode guarantees) around the test router and transform wrappers; update the test harness to provide properly typed fakes instead of casting. Concretely, add a typed helper for building SSR routers (refactor createRealSsrRouter to accept and return precise generics) and create typed transform wrappers used in transformStreamWithRouter.test so callers of BaseRootRoute, BaseRoute, createTestRouter and createMemoryHistory no longer require `as any`; update usages at the noted locations (including the other occurrences around lines 223-226 and 946-950) to use the new typed helpers and remove the `as any` casts. Ensure the new helpers' signatures reflect the real route/component types so the TypeScript compiler enforces strict-mode types across the tests.packages/router-core/tests/ssr-server-cleanup.test.ts (1)
18-18: ⚡ Quick winReduce
anyusage in new test helpers/calls to keep strict typing coverage meaningful.Please replace
Record<string, any>andas anycasts here withunknown/narrowed helper types (e.g., typed fake router/stream aliases). This keeps tests aligned with strict-mode guarantees.As per coding guidelines
**/*.{ts,tsx}: Use TypeScript strict mode with extensive type safety.Also applies to: 364-370
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/router-core/tests/ssr-server-cleanup.test.ts` at line 18, The test helper buildRouter currently types its parameter as Record<string, any> and uses as any casts; replace that broad any with a stricter type (e.g., unknown or a narrow helper interface like DehydratedState | undefined) and update callers to narrow/validate that data before use; also remove any "as any" casts in this file (and the other occurrences around the 364-370 area) by introducing small test-only types or typed fake router/stream aliases (e.g., FakeRouter, FakeStream) and use type guards or explicit conversion helpers to map unknown to those types so the tests remain strictly typed under TS strict mode while preserving the same runtime behavior.🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. Inline comments: In `@e2e/react-start/streaming-ssr/tests/query-heavy.spec.ts`: - Around line 144-145: The test currently checks for the broad substring 'slow-async' which can match static markup; update the assertions in query-heavy.spec.ts to assert against a concrete payload-specific token from the stream (e.g., the exact streamed value token emitted for the slow async query) instead of the generic 'slow-async' substring; specifically, change the two expectations that use html.indexOf('slow-async') to search for the exact payload token string (still using html and endIndex) and assert that its index is >= 0 and < endIndex so the streamed payload ordering is validated precisely. In `@packages/router-core/src/ssr/handlerCallback.ts`: - Around line 45-57: The dispose function currently returns immediately after a successful await on response.body!.cancel(reason), which prevents router.serverSsr?.cleanup() from running; modify dispose (the async dispose method that checks disposed) to always invoke router.serverSsr?.cleanup() after attempting response.body!.cancel(reason) — e.g., remove the premature return and/or use try/finally so that regardless of successful cancel or thrown errors, router.serverSsr?.cleanup() is executed (keep the disposed guard as-is). In `@packages/router-core/src/ssr/transformStreamWithRouter.ts`: - Around line 21-24: Update the transformReadableStreamWithRouter signature to type routerStream as ReadableStream<Uint8Array | string> (and adjust any other file functions that currently use untyped ReadableStream similarly), update related types such as TransformStreamWithRouterOptions to reflect the stricter union where used, and remove the ArrayBufferView cast-paths inside the implementation; instead branch on chunk type (string vs Uint8Array) and handle conversions explicitly (e.g., TextEncoder/decoder or direct passthrough) so no unsafe ArrayBufferView casts remain and TypeScript strict mode is satisfied. In `@packages/router-core/tests/closing-tag-detection.bench.ts`: - Around line 266-269: The function findBodyEndTagNativeLowerThenLastOpenSlash currently searches for the literal lowercase BODY_END_TAG in the original string and skips the fallback, causing mixed-case tags like </BODY> to be missed; change it to perform a case-insensitive lastIndexOf by searching on a lowercased copy of the input (e.g., const lower = str.toLowerCase(); const index = lower.lastIndexOf(BODY_END_TAG)) and then return index === -1 ? findBodyEndTagLastOpenSlash(str) : index so the index stays valid and mixed-case tags are found. In `@packages/start-server-core/src/createStartHandler.ts`: - Around line 223-233: The setResponse helper currently overwrites the module-scoped streamResponse when an SsrResponse with serverSsrCleanup === 'stream' arrives, leaking the previous stream; make setResponse async, check if streamResponse exists and call its disposal/cleanup method (or await any provided cleanup promise) before assigning the new stream, retain the isSsrResponse and serverSsrCleanup checks, and update all call sites to await setResponse(...) so disposal completes before continuing. --- Nitpick comments: In `@packages/react-router/tests/renderRouterToStream.test.tsx`: - Around line 23-34: The helper buildRouter does not consistently dehydrate the server SSR state; update buildRouter to call and await router.serverSsr!.dehydrate() after attachRouterServerSsrUtils({ router, manifest: undefined }) and after await router.load(), so that the router is always dehydrated before return; locate the function buildRouter and add the await router.serverSsr!.dehydrate() invocation (using the existing router.serverSsr property) prior to returning the router. In `@packages/router-core/tests/ssr-server-cleanup.test.ts`: - Line 18: The test helper buildRouter currently types its parameter as Record<string, any> and uses as any casts; replace that broad any with a stricter type (e.g., unknown or a narrow helper interface like DehydratedState | undefined) and update callers to narrow/validate that data before use; also remove any "as any" casts in this file (and the other occurrences around the 364-370 area) by introducing small test-only types or typed fake router/stream aliases (e.g., FakeRouter, FakeStream) and use type guards or explicit conversion helpers to map unknown to those types so the tests remain strictly typed under TS strict mode while preserving the same runtime behavior. In `@packages/router-core/tests/transformStreamWithRouter.test.ts`: - Around line 185-199: Tests repeatedly use `as any` casts (weakening strict-mode guarantees) around the test router and transform wrappers; update the test harness to provide properly typed fakes instead of casting. Concretely, add a typed helper for building SSR routers (refactor createRealSsrRouter to accept and return precise generics) and create typed transform wrappers used in transformStreamWithRouter.test so callers of BaseRootRoute, BaseRoute, createTestRouter and createMemoryHistory no longer require `as any`; update usages at the noted locations (including the other occurrences around lines 223-226 and 946-950) to use the new typed helpers and remove the `as any` casts. Ensure the new helpers' signatures reflect the real route/component types so the TypeScript compiler enforces strict-mode types across the tests. In `@packages/solid-router/tests/renderRouterToStream.test.tsx`: - Around line 34-46: Add a call to dehydrate the server SSR state in buildRouter: after attaching SSR utils with attachRouterServerSsrUtils({ router, manifest: undefined }) and finishing router.load(), invoke await router.serverSsr!.dehydrate() so the router is put into the same SSR-dehydrated state used by other tests; reference the buildRouter function and the router.serverSsr!.dehydrate() method when making this change. In `@packages/start-server-core/src/createStartHandler.ts`: - Around line 214-217: The executeMiddleware signature (and analogous spots at the other occurrences) uses TODO/any for middleware and ctx; replace these with concrete, strict types: define a RequestContext (or reuse existing context type used across the SSR pipeline) for ctx, a Middleware type like (ctx: RequestContext) => Promise<void | HandlerCallbackResult | Response> (or synchronous equivalents), and ensure executeMiddleware returns Promise<{ ctx: RequestContext; response: HandlerCallbackResult }>; update any intermediate helper types (e.g., HandlerCallbackResult) so their shape is explicit (status, headers, body, etc.), and propagate these concrete types into the other two locations referenced so the cleanup path enforces correct shapes rather than any/ TODO. In `@packages/start-server-core/tests/createStartHandler.test.ts`: - Around line 72-82: Replace the repeated `as any` casts by introducing small test-only types and helper factories: add a TypedTestRouter (or TestRouter) interface representing the minimal router shape used by attachRouterServerSsrUtils and createSsrStreamResponse, and a helper function (e.g., makeTestRouter()) that returns a strongly-typed instance; likewise add a TypedSsrResponse or makeTestSsrResponse(stream) helper that returns Response with the proper typed serverSsr attached. Update calls to attachRouterServerSsrUtils({ router: router as any, ... }) and createSsrStreamResponse(router as any, ...) to use the new test helpers or typed variables (router: TestRouter) so the code at symbols attachRouterServerSsrUtils and createSsrStreamResponse no longer needs `as any`; apply the same pattern to the other occurrences listed (lines ~106-107, 129-130, 189-190, 217-218, 251-252, 277-278, 304-305). In `@packages/vue-router/tests/renderRouterToStream.test.tsx`: - Around line 40-52: The helper buildRouter sets up server SSR utils but does not call the server-side dehydrate step, causing inconsistent setup vs tests that call router.serverSsr!.dehydrate() manually; update buildRouter to await router.serverSsr!.dehydrate() after attachRouterServerSsrUtils({ router, manifest: undefined }) and before returning the router (or document in a comment why a specific test should call dehydrate itself), so tests can rely on buildRouter returning a fully dehydrated server router.🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
252d919e-92b8-4f8b-b32d-6675ad3b362e📥 Commits
Reviewing files that changed from the base of the PR and between bae50be10aed6b1a2f95fd17b1fb8ff9efdf309c and f680d151f5913b44ef48d995df172a24021ada14.
📒 Files selected for processing (37)
.changeset/fuzzy-jobs-eat.mde2e/react-start/streaming-ssr/tests/query-heavy.spec.tse2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/index-BwsVWHwV.jse2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/index-ElfLiipA.csse2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/index-rPfEOKs3.jse2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/lazy-page.lazy-BzoMuhUY.jse2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/lazy-with-loader-page.lazy-BzLmn584.jse2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/normal-page-BPOVyYTF.jse2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/page-with-search-BhJv4yJI.jse2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/scroll-block-BAas_Ct-.jse2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/virtual-page.lazy-BCqvdivF.jse2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/index.htmlpackages/react-router/src/ssr/renderRouterToStream.tsxpackages/react-router/tests/renderRouterToStream.test.tsxpackages/router-core/src/router.tspackages/router-core/src/ssr/createRequestHandler.tspackages/router-core/src/ssr/handlerCallback.tspackages/router-core/src/ssr/server.tspackages/router-core/src/ssr/ssr-server.tspackages/router-core/src/ssr/transformStreamWithRouter.tspackages/router-core/tests/closing-tag-detection.bench.tspackages/router-core/tests/ssr-server-cleanup.test.tspackages/router-core/tests/transformStreamBackpressure.perf.test.tspackages/router-core/tests/transformStreamWithRouter.test.tspackages/router-core/vite.config.tspackages/router-ssr-query-core/package.jsonpackages/router-ssr-query-core/src/index.tspackages/router-ssr-query-core/tests/index.test.tspackages/router-ssr-query-core/vite.config.tspackages/solid-router/src/ssr/renderRouterToStream.tsxpackages/solid-router/tests/renderRouterToStream.test.tsxpackages/start-server-core/src/createStartHandler.tspackages/start-server-core/tests/createStartHandler.test.tspackages/start-server-core/tests/fixtures/start-manifest.tspackages/start-server-core/vite.config.tspackages/vue-router/src/ssr/renderRouterToStream.tsxpackages/vue-router/tests/renderRouterToStream.test.tsx
💤 Files with no reviewable changes (9)
- e2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/normal-page-BPOVyYTF.js
- e2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/page-with-search-BhJv4yJI.js
- e2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/lazy-with-loader-page.lazy-BzLmn584.js
- e2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/lazy-page.lazy-BzoMuhUY.js
- e2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/index-ElfLiipA.css
- e2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/virtual-page.lazy-BCqvdivF.js
- e2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/index-rPfEOKs3.js
- e2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/assets/scroll-block-BAas_Ct-.js
- e2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/index.html
e2e/react-start/streaming-ssr/tests/query-heavy.spec.ts lines 144 to 145OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -128,3 +128,18 @@128128 .count()129129 expect(serverSourceCount).toBe(9)130130 })131+132+ test('emits query stream data before stream end marker', async ({133+ request,134+ }) => {135+ const response = await request.get('/query-heavy')136+ const html = await response.text()137+ const endMarker = '$_TSR.e()'138+ const endIndex = html.indexOf(endMarker)139+ const lastScriptOpen = html.lastIndexOf('<script', endIndex)140+ const lastScriptClose = html.lastIndexOf('</script>', endIndex)141+142+ expect(endIndex).toBeGreaterThan(-1)143+ expect(lastScriptOpen).toBeGreaterThan(lastScriptClose)144+ expect(html.indexOf('slow-async')).toBeGreaterThan(-1)145+ expect(html.indexOf('slow-async')).toBeLessThan(endIndex)⚠️ Potential issue | 🟡 Minor | ⚡ Quick win
Use a payload-specific token instead of the broad
slow-asyncsubstring.This can match static markup (e.g.,
slow-async-query-*) and pass even when streamed query data ordering regresses. Assert against a concrete streamed value token.🔧 Suggested assertion tightening
- expect(html.indexOf('slow-async')).toBeGreaterThan(-1) - expect(html.indexOf('slow-async')).toBeLessThan(endIndex) + const slowAsyncValue = 'slow-async-1' + const slowAsyncIndex = html.indexOf(slowAsyncValue) + expect(slowAsyncIndex).toBeGreaterThan(-1) + expect(slowAsyncIndex).toBeLessThan(endIndex)📝 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.
Suggested change144- expect(html.indexOf('slow-async')).toBeGreaterThan(-1)145- expect(html.indexOf('slow-async')).toBeLessThan(endIndex)144+ const slowAsyncValue = 'slow-async-1'145+ const slowAsyncIndex = html.indexOf(slowAsyncValue)146+ expect(slowAsyncIndex).toBeGreaterThan(-1)147+ expect(slowAsyncIndex).toBeLessThan(endIndex)🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@e2e/react-start/streaming-ssr/tests/query-heavy.spec.ts` around lines 144 - 145, The test currently checks for the broad substring 'slow-async' which can match static markup; update the assertions in query-heavy.spec.ts to assert against a concrete payload-specific token from the stream (e.g., the exact streamed value token emitted for the slow async query) instead of the generic 'slow-async' substring; specifically, change the two expectations that use html.indexOf('slow-async') to search for the exact payload token string (still using html and endIndex) and assert that its index is >= 0 and < endIndex so the streamed payload ordering is validated precisely.✅ Addressed in commit ef37315
packages/router-core/src/ssr/handlerCallback.ts lines 45 to 56Resolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -2,0 +37,21 @@37+ if (!response.body) {38+ throw new Error('Invariant failed: SSR stream response requires a body')39+ }40+41+ let disposed = false42+ return {43+ response,44+ serverSsrCleanup: 'stream',45+ async dispose(reason?: unknown) {46+ if (disposed) return47+ disposed = true48+49+ try {50+ await response.body!.cancel(reason)51+ return52+ } catch {53+ // ignore; fallback cleanup below still releases router SSR state54+ }55+56+ router.serverSsr?.cleanup()57+ },⚠️ Potential issue | 🟠 Major | ⚡ Quick win
dispose()skips SSR cleanup on the successful cancel path.Line 51 returns immediately after
response.body.cancel(reason), so Line 56 never runs when cancel succeeds. That can leave router SSR request state alive when this response is replaced/stripped.💡 Suggested fix
async dispose(reason?: unknown) { if (disposed) return disposed = true try { - await response.body!.cancel(reason) - return + await response.body!.cancel(reason) } catch { // ignore; fallback cleanup below still releases router SSR state + } finally { + router.serverSsr?.cleanup() } - - router.serverSsr?.cleanup() },🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/router-core/src/ssr/handlerCallback.ts` around lines 45 - 57, The dispose function currently returns immediately after a successful await on response.body!.cancel(reason), which prevents router.serverSsr?.cleanup() from running; modify dispose (the async dispose method that checks disposed) to always invoke router.serverSsr?.cleanup() after attempting response.body!.cancel(reason) — e.g., remove the premature return and/or use try/finally so that regardless of successful cancel or thrown errors, router.serverSsr?.cleanup() is executed (keep the disposed guard as-is).✅ Addressed in commit ef37315
@@ -4,5 +4,21 @@44 import type { AnyRouter } from '../router'556+export type TransformStreamWithRouterOptions = {7+ /** Timeout for serialization to complete after app render finishes (default: 60000ms) */8+ timeoutMs?: number9+ /** Maximum lifetime of the stream transform (default: 120000ms). Safety net for cleanup. */10+ lifetimeMs?: number11+ /**12+ * Called exactly once when the stream is torn down due to abort/error/13+ * cancel/timeout — NOT on natural successful completion. Use this to14+ * abort a hidden producer upstream of any PassThrough you passed in15+ * (e.g. React `renderToPipeableStream`'s `abort()`).16+ * Errors thrown from this callback are swallowed.17+ */18+ onAbort?: (reason?: unknown) => void19+}20+621 export function transformReadableStreamWithRouter(722 router: AnyRouter,823 routerStream: ReadableStream,24+ opts?: TransformStreamWithRouterOptions,🛠️ Refactor suggestion | 🟠 Major | ⚡ Quick win
Tighten stream chunk typing to avoid unsafe casts in the core transform path.
These signatures use untyped
ReadableStream, which forces downstream coercion. Please type the stream asReadableStream<Uint8Array | string>(or the exact supported union) and remove theArrayBufferViewcast path where possible.As per coding guidelines
**/*.{ts,tsx}: Use TypeScript strict mode with extensive type safety.Also applies to: 199-203, 781-785
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/router-core/src/ssr/transformStreamWithRouter.ts` around lines 21 - 24, Update the transformReadableStreamWithRouter signature to type routerStream as ReadableStream<Uint8Array | string> (and adjust any other file functions that currently use untyped ReadableStream similarly), update related types such as TransformStreamWithRouterOptions to reflect the stricter union where used, and remove the ArrayBufferView cast-paths inside the implementation; instead branch on chunk type (string vs Uint8Array) and handle conversions explicitly (e.g., TextEncoder/decoder or direct passthrough) so no unsafe ArrayBufferView casts remain and TypeScript strict mode is satisfied.@@ -202,0 +249,21 @@249+250+ if (251+ (str.charCodeAt(start + 2) | 32) === 98 &&252+ (str.charCodeAt(start + 3) | 32) === 111 &&253+ (str.charCodeAt(start + 4) | 32) === 100 &&254+ (str.charCodeAt(start + 5) | 32) === 121 &&255+ str.charCodeAt(start + 6) === 62256+ ) {257+ return start258+ }259+260+ searchFrom = start - 1261+ }262+263+ return -1264+}265+266+function findBodyEndTagNativeLowerThenLastOpenSlash(str: string): number {267+ const index = str.lastIndexOf(BODY_END_TAG)268+ return index === -1 ? findBodyEndTagLastOpenSlash(str) : index269+}⚠️ Potential issue | 🟡 Minor | ⚡ Quick win
Case-insensitive “last
</body>” detection is incorrect in mixed-case input.This shortcut returns the last lowercase
</body>and skips fallback, so a later uppercase</BODY>is missed.Suggested fix
function findBodyEndTagNativeLowerThenLastOpenSlash(str: string): number { - const index = str.lastIndexOf(BODY_END_TAG) - return index === -1 ? findBodyEndTagLastOpenSlash(str) : index + // Keep this variant correct for mixed-case tails; "native lowercase first" + // can miss a later uppercase </BODY>. + return findBodyEndTagLastOpenSlash(str) }🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/router-core/tests/closing-tag-detection.bench.ts` around lines 266 - 269, The function findBodyEndTagNativeLowerThenLastOpenSlash currently searches for the literal lowercase BODY_END_TAG in the original string and skips the fallback, causing mixed-case tags like </BODY> to be missed; change it to perform a case-insensitive lastIndexOf by searching on a lowercased copy of the input (e.g., const lower = str.toLowerCase(); const index = lower.lastIndexOf(BODY_END_TAG)) and then return index === -1 ? findBodyEndTagLastOpenSlash(str) : index so the index stays valid and mixed-case tags are found.@@ -206,2 +214,20 @@206-function executeMiddleware(middlewares: Array<TODO>, ctx: TODO): Promise<TODO> {214+async function executeMiddleware(215+ middlewares: Array<TODO>,216+ ctx: TODO,217+): Promise<{ ctx: TODO; response: HandlerCallbackResult }> {207218 let index = -1219+ let streamResponse:220+ | Extract<SsrResponse, { serverSsrCleanup: 'stream' }>221+ | undefined222+223+ const setResponse = (response: TODO) => {224+ if (isSsrResponse(response)) {225+ if (response.serverSsrCleanup === 'stream') {226+ streamResponse = response227+ }228+ ctx.response = response.response229+ return230+ }231+232+ ctx.response = response233+ }⚠️ Potential issue | 🟠 Major | 🏗️ Heavy lift
Dispose previously tracked stream before overwriting
streamResponse.When a second streaming
SsrResponseis assigned, the previous tracked stream handle is overwritten without disposal. That can leak SSR cleanup ownership for the earlier stream in the same middleware chain.Proposed direction
- const setResponse = (response: TODO) => { + const setResponse = async (response: TODO) => { if (isSsrResponse(response)) { if (response.serverSsrCleanup === 'stream') { + if (streamResponse && streamResponse !== response) { + await streamResponse.dispose('middleware stream replaced') + } streamResponse = response } ctx.response = response.response return } ctx.response = response }Then
await setResponse(...)at call sites.🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@packages/start-server-core/src/createStartHandler.ts` around lines 223 - 233, The setResponse helper currently overwrites the module-scoped streamResponse when an SsrResponse with serverSsrCleanup === 'stream' arrives, leaking the previous stream; make setResponse async, check if streamResponse exists and call its disposal/cleanup method (or await any provided cleanup promise) before assigning the new stream, retain the isSsrResponse and serverSsrCleanup checks, and update all call sites to await setResponse(...) so disposal completes before continuing.there can only be a single SSR response per request
@schiller-manuel, understood — since the architecture guarantees at most one SSR response per request, the overwrite scenario I was worried about can't occur. My concern doesn't apply here. Thanks for the clarification!Merging this PR will not alter performance#
✅ 4untouched benchmarks⏩ 2skipped benchmarks1
Comparingfix-streaming(0c0a6cc) withmain(c79b396)Footnotes#
-
2 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. ↩
-
Sign in to join this conversation.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID:
2935563a-e4f8-470a-8fcb-c22d12005e1b📥 Commits
Reviewing files that changed from the base of the PR and between f680d151f5913b44ef48d995df172a24021ada14 and 0c0a6cce6d0fcf7ff9561396ecf1c885aab0fdbb.
📒 Files selected for processing (3)
e2e/react-start/streaming-ssr/tests/query-heavy.spec.tspackages/router-core/src/ssr/handlerCallback.tspackages/router-core/tests/transformStreamWithRouter.test.ts💤 Files with no reviewable changes (1)
📝 Walkthrough
Walkthrough#
Adds SSR-aware response types and normalization, refactors server-SSR lifecycle and script buffering, implements a backpressure-safe transformStreamWithRouter (fast/main paths and HTML boundary detection), wires abort/cleanup into React/Solid/Vue/start-server flows, strengthens query SSR teardown, and adds extensive tests/benchmarks.
Changes#
SSR Streaming, Abort Handling & Cleanup
packages/router-core/src/ssr/handlerCallback.ts,packages/router-core/src/ssr/server.tsSsrResponse/HandlerCallbackResultadded;isSsrResponse/normalizeSsrResponse;createSsrStreamResponseenforces body + idempotent dispose;replaceSsrResponse&stripSsrResponseBodymanage body replacement and cleanup downgrade.packages/router-core/src/router.tsServerSsraddsreserveStreamFastPath,onInjectedHtml,onCleanup;RouterSsrLifecycleandserverSsrLifecycleoption added;dehydratenow returnsAwaitable.packages/router-core/src/ssr/createRequestHandler.tsSsrResponse, computesresponseOwnsCleanupfromserverSsrCleanup === 'stream', returns normalizedresponse, and defers/invokes cleanup accordingly.packages/router-core/src/ssr/ssr-server.tsfinishScriptSerialization()coordination,reserveStreamFastPath(), and reentrancy-safecleanup()with attach-time lifecycle hooks.packages/router-core/tests/closing-tag-detection.bench.tsfindHtmlBoundaryand multiple detection variants implemented; verification and benchmarks added for</body>detection and boundary scans.packages/router-core/src/ssr/transformStreamWithRouter.ts,packages/router-core/tests/transformStreamWithRouter.test.tsTransformStreamWithRouterOptionsincludingonAbort, serialization gating, timeouts, and extensive tests.packages/react-router/src/ssr/renderRouterToStream.tsx,packages/react-router/tests/renderRouterToStream.test.tsxwaitForReadyOrAbortfor bots, robust pipeable/readable abort/error handling, passesonAbortto transform, returnscreateSsrStreamResponse; tests cover sync/async errors and aborts.packages/solid-router/src/ssr/renderRouterToStream.tsx,packages/solid-router/tests/renderRouterToStream.test.tsxwaitForReadyOrAbort,solidWritableproxy forpipeTo,onAbortwiring, and SsrStreamResponse wrapping; tests for bot-abort and pipeTo rejection.packages/vue-router/src/ssr/renderRouterToStream.tsx,packages/vue-router/tests/renderRouterToStream.test.tsxprependDoctypereader lifecycle; bot render-to-string raced with abort; streaming path uses TransformStream-backed writable proxy, abort listener cleanup,onAbortto transform, and SsrStreamResponse wrapping; tests validate marker placement, pipe errors, and aborts.packages/start-server-core/src/createStartHandler.ts,packages/start-server-core/tests/createStartHandler.test.tsexecuteMiddlewarenormalized to return{ ctx, response }, detectsSsrResponse, centralizes response assignment and disposal,handleRedirectResponse/HEAD handling usereplaceSsrResponse/stripSsrResponseBody; tests assert cleanup-ownership across middleware flows.packages/router-ssr-query-core/src/index.ts,packages/router-ssr-query-core/package.json,packages/router-ssr-query-core/vite.config.tsserverSsrLifecycle.onServerSsrAttachto close streams/unsubscribe/cancel/clear; guardscreatePushableStream()terminal ops; package.json test script fixed; Vitest GC gating config added.packages/router-ssr-query-core/tests/index.test.tspackages/router-core/tests/ssr-server-cleanup.test.ts,packages/router-core/tests/transformStreamWithRouter.test.ts,packages/router-core/tests/transformStreamBackpressure.perf.test.ts,packages/router-core/vite.config.tse2e/react-start/streaming-ssr/tests/query-heavy.spec.ts,e2e/vue-router/scroll-restoration-sandbox-vite/dist-hash/*Estimated code review effort#
🎯 4 (Complex) | ⏱️ ~60 minutes
Suggested reviewers#
✨ Finishing Touches
📝 Generate docstrings
🧪 Generate unit tests (beta)