Skip to content

feat(rsbuild): add RSC support#7366

Open
SyMind wants to merge 14 commits into
TanStack:mainfrom
SyMind:rsb
Open

feat(rsbuild): add RSC support#7366
SyMind wants to merge 14 commits into
TanStack:mainfrom
SyMind:rsb

Conversation

@SyMind
Copy link
Copy Markdown

@SyMind SyMind commented May 8, 2026

  • Add Rsbuild RSC SSR decode support by collecting client reference chunks from Flight import rows and exposing them as SSR client preload dependencies.
  • Update Rsbuild RSC CSS handling to use explicit data-rsc-css-href markers, avoiding accidental preinit of ordinary React 19 stylesheet resources.
  • Move Rsbuild client build assets from static/* to assets/* subdirectories and update the dev client entry URL accordingly.
  • Override @rspack/core to the required canary build for current RSC integration support.

Summary by CodeRabbit

  • Chores

    • Updated @rsbuild/core dependency to v2.0.6 across build and example projects.
    • Added @rspack/core override for canary version support.
  • Bug Fixes

    • Improved CSS stylesheet handling in React Server Component asset collection during SSR rendering.
  • Improvements

    • Enhanced RSC Flight stream processing to better extract and preload client-side dependencies.

Review Change Stack

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 8, 2026

📝 Walkthrough

Walkthrough

This PR upgrades Rsbuild from ^2.0.1 to ^2.0.6 across the test, example, and package suite, pins Rspack to a specific canary version, implements RSC Flight stream parsing for client reference preload collection during SSR, introduces a configurable assets directory structure, and updates CSS stylesheet link collection to require explicit markup.

Changes

Rsbuild 2.0.6 Upgrade & RSC Flight Preload Collection

Layer / File(s) Summary
Rsbuild and Rspack dependency upgrades
benchmarks/bundle-size/package.json, e2e/*/package.json, examples/*/package.json, packages/*/package.json, package.json
@rsbuild/core bumped from ^2.0.1 to ^2.0.6 in 18 package.json files. Root pnpm.overrides adds @rspack/core pinned to canary 2.0.4-canary-32cafdc6-20260518042857.
Rsbuild client assets directory configuration
packages/start-plugin-core/src/rsbuild/planning.ts, packages/start-plugin-core/src/rsbuild/plugin.ts, packages/start-plugin-core/src/rsbuild/virtual-modules.ts
Export RSBUILD_CLIENT_ASSETS_DIR constant ('assets') and apply explicit subdirectory mappings for client build outputs. Update dev entry URL from /static/js/index.js to /assets/js/index.js. Update JSDoc example path.
RSC Flight stream decoding with client reference preload collection
packages/react-start-rsc/src/rsbuild/ssr-decode.ts
Replace direct Rsbuild export with wrapper that, when onClientReference callback is set and stream supports tee(), concurrently scans one stream branch for Flight protocol metadata while decoding from the other. Extract client reference IDs and chunk filenames, prefix JS paths with module-loading prefix, invoke callback with { id, deps: { js, css: [] }, runtime: 'rsbuild' } for preload collection. Fall back to original behavior if callback absent or tee() unavailable.
RSC ServerPlugin CSS link configuration
packages/start-plugin-core/src/rsbuild/plugin.ts
Add cssLink config to RSC ServerPlugin options with precedence: false and empty data-rsc-css-href prop.
CSS stylesheet link collection and serialization updates
packages/react-start-rsc/src/awaitLazyElements.ts, packages/react-start-rsc/src/serialization.server.ts
Update findPendingLazyPayloads to extract CSS href from stylesheet <link rel="stylesheet"> elements only when data-rsc-css-href prop exists. Add documentation explaining that collected assets are injected only during actual RSC tree rendering under Rsbuild. Update JSDoc to reflect explicit marking requirement.

Sequence Diagram

sequenceDiagram
  participant SSRRenderer as SSR Renderer
  participant Wrapper as createFromReadableStreamCollectingClientPreloads
  participant Stream as ReadableStream
  participant Decoder as createFromReadableStream
  participant Scanner as collectClientReferencePreloads
  participant Callback as onClientReference

  SSRRenderer->>Wrapper: stream, options
  Wrapper->>Stream: tee()
  Wrapper->>Decoder: branch1
  Wrapper->>Scanner: branch2
  par
    Decoder-->>Wrapper: decoded RSC
  and
    loop each buffered row
      Scanner->>Scanner: parse metadata
      Scanner->>Scanner: extract [id, chunks]
      Scanner->>Callback: emit preload info
    end
    Scanner-->>Wrapper: collection done
  end
  Wrapper->>SSRRenderer: RSC result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • TanStack/router#7245: Earlier @rsbuild/core dependency version bump to ^2.0.1 in the same package.json files.

Suggested labels

package: react-start

Suggested reviewers

  • beaussan
  • SeanCassiere
  • Sheraff

Poem

🐰 The Stream now sings in harmony,
With tee'd branches reading preloads free,
CSS links wear their markers proud,
Assets flow through the async cloud,
Rsbuild hops to version new, what a view! 🚀

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'feat(rsbuild): add RSC support' accurately describes the main changes: adding RSC (React Server Components) support for Rsbuild, including SSR decode support, CSS handling updates, and asset directory restructuring.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
⚔️ Resolve merge conflicts
  • Resolve merge conflict in branch rsb

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 and usage tips.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 8, 2026

Bundle Size Benchmarks

  • Commit: 4eed408f127b
  • Measured at: 2026-05-09T10:56:31.909Z
  • Baseline source: history:35e88f04996d
  • Dashboard: bundle-size history
Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 87.29 KiB +139 B (+0.16%) 87.15 KiB 274.07 KiB 75.81 KiB ▁▁▁▁▁▁▁▁▁▁▁█
react-router.full 90.82 KiB +141 B (+0.15%) 90.68 KiB 285.58 KiB 78.82 KiB ▁▁▁▁▁▁▁▁▁▁▁█
solid-router.minimal 35.51 KiB +126 B (+0.35%) 35.38 KiB 106.36 KiB 31.91 KiB ▁▁▁▁▁▁▁▁▁▁▁█
solid-router.full 40.23 KiB +127 B (+0.31%) 40.10 KiB 120.58 KiB 36.14 KiB ▁▁▁▁▁▁▁▁▁▁▁█
vue-router.minimal 53.28 KiB +131 B (+0.24%) 53.15 KiB 151.51 KiB 47.83 KiB ▁▁▁▁▁▁▁▁▁▁▁█
vue-router.full 58.41 KiB +133 B (+0.22%) 58.28 KiB 167.68 KiB 52.30 KiB ▁▁▁▁▁▁▁▁▁▁▁█
react-start.minimal 101.97 KiB +141 B (+0.14%) 101.84 KiB 322.51 KiB 88.13 KiB ▁▁▁▁▁▁▁▁▁▁▃█
react-start.full 105.41 KiB +140 B (+0.13%) 105.27 KiB 332.84 KiB 91.10 KiB ▁▁▁▁▁▁▁▁▁▁▄█
react-start.rsbuild.minimal 99.59 KiB +171 B (+0.17%) 99.42 KiB 316.97 KiB 85.66 KiB ▁▁▁▁▁▁▁▁▁▁▄█
react-start.rsbuild.full 102.89 KiB +172 B (+0.16%) 102.72 KiB 327.41 KiB 88.45 KiB ▁▁▁▁▁▁▁▁▁▁▃█
solid-start.minimal 49.61 KiB +131 B (+0.26%) 49.48 KiB 152.48 KiB 43.79 KiB ▁▁▁▁▁▁▁▁▁▁▄█
solid-start.full 55.40 KiB +133 B (+0.24%) 55.27 KiB 169.39 KiB 48.70 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.

@SyMind SyMind marked this pull request as ready for review May 13, 2026 03:15
Copy link
Copy Markdown
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: 3

🤖 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 `@packages/react-start-rsc/src/awaitLazyElements.ts`:
- Around line 37-41: The code assigns el.props.href (of any type) to cssHref and
passes it to cssCollector without a runtime type check; update the logic in
awaitLazyElements (the block using cssHref, cssCollector and the
'data-rsc-css-href' prop) to verify typeof el.props.href === 'string' before
assigning to cssHref or invoking cssCollector, ensuring cssHref remains a string
| undefined and only string values are passed into CssHrefCollector; keep the
existing conditional flow ('data-rsc-css-href' in el.props then cssHref &&
cssCollector) but add the runtime typeof guard to satisfy strict TypeScript
safety.

In `@packages/react-start-rsc/src/rsbuild/ssr-decode.ts`:
- Around line 154-157: The options parameter in
createFromReadableStreamCollectingClientPreloads is weakly typed as object;
replace it with the upstream decoder options type used by
react-server-dom-rspack (import the exact options type from the upstream
createFromReadableStream signature) and use that type for the options parameter
and any related variables so the function matches the upstream API (function
name: createFromReadableStreamCollectingClientPreloads; reference the
createFromReadableStream signature/type from react-server-dom-rspack to import
the correct type and update usages accordingly).
- Around line 178-180: If createFromReadableStream<T>(decodeStream, options)
throws, preloadPromise from the concurrent stream scanner is never awaited which
can produce unhandled rejections; always observe (await or attach a .catch) to
preloadPromise irrespective of success or failure of createFromReadableStream so
the scanner's promise is always settled (e.g., wrap the createFromReadableStream
call in try/finally and await preloadPromise in the finally block or add
preloadPromise.catch(() => {}) before returning/throwing). Also tighten the type
of options (replace the loose options?: object with the exact upstream signature
used by createFromReadableStream) so the function signature matches upstream and
preserves type safety.
🪄 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: fde7317d-a03e-46de-9164-4c51b448a2c9

📥 Commits

Reviewing files that changed from the base of the PR and between 4eed408 and 74c04a1.

⛔ Files ignored due to path filters (1)
  • pnpm-lock.yaml is excluded by !**/pnpm-lock.yaml
📒 Files selected for processing (29)
  • benchmarks/bundle-size/package.json
  • e2e/react-router/rspack-basic-file-based/package.json
  • e2e/react-router/rspack-basic-virtual-named-export-config-file-based/package.json
  • e2e/react-start/basic/package.json
  • e2e/react-start/css-inline/package.json
  • e2e/react-start/custom-server-rsbuild/package.json
  • e2e/react-start/hmr/package.json
  • e2e/react-start/import-protection/package.json
  • e2e/react-start/rsc/package.json
  • e2e/react-start/server-functions/package.json
  • e2e/solid-router/rspack-basic-file-based/package.json
  • e2e/solid-router/rspack-basic-virtual-named-export-config-file-based/package.json
  • e2e/solid-start/basic/package.json
  • e2e/vue-router/rspack-basic-file-based/package.json
  • e2e/vue-router/rspack-basic-virtual-named-export-config-file-based/package.json
  • e2e/vue-start/basic/package.json
  • examples/react/quickstart-rspack-file-based/package.json
  • examples/solid/quickstart-rspack-file-based/package.json
  • package.json
  • packages/react-start-rsc/src/awaitLazyElements.ts
  • packages/react-start-rsc/src/rsbuild/ssr-decode.ts
  • packages/react-start-rsc/src/serialization.server.ts
  • packages/react-start/package.json
  • packages/solid-start/package.json
  • packages/start-plugin-core/package.json
  • packages/start-plugin-core/src/rsbuild/planning.ts
  • packages/start-plugin-core/src/rsbuild/plugin.ts
  • packages/start-plugin-core/src/rsbuild/virtual-modules.ts
  • packages/vue-start/package.json

Comment on lines +37 to 41
let cssHref: string | undefined
if ('data-rsc-css-href' in el.props) {
cssHref = el.props.href
}
if (cssHref && cssCollector) {
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Inspect marker-based href extraction and current lack of string guard.
rg -n -C3 "data-rsc-css-href|cssHref = el.props.href|cssCollector\\(" packages/react-start-rsc/src/awaitLazyElements.ts

Repository: TanStack/router

Length of output: 322


🏁 Script executed:

#!/bin/bash
# Get the full function context to understand types
head -80 packages/react-start-rsc/src/awaitLazyElements.ts | tail -80

Repository: TanStack/router

Length of output: 2466


🏁 Script executed:

#!/bin/bash
# Search for cssCollector definition and type signature
rg -n "cssCollector" packages/react-start-rsc/src/awaitLazyElements.ts -B 5 -A 5

Repository: TanStack/router

Length of output: 1717


🏁 Script executed:

#!/bin/bash
# Look for the function signature and parameter types
rg -n "function|const.*=.*\(" packages/react-start-rsc/src/awaitLazyElements.ts | head -20

Repository: TanStack/router

Length of output: 185


Guard href type before sending it to cssCollector.

At line 39, el.props.href comes from any and lacks a runtime type check before assignment to cssHref. Since CssHrefCollector expects (href: string) => void, a non-string value could violate the contract.

Proposed fix
-    let cssHref: string | undefined
-    if ('data-rsc-css-href' in el.props) {
-      cssHref = el.props.href
-    }
+    const cssHref =
+      'data-rsc-css-href' in el.props && typeof el.props.href === 'string'
+        ? el.props.href
+        : undefined

Per coding guidelines, **/*.{ts,tsx} must use TypeScript strict mode with extensive type safety.

📝 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 change
let cssHref: string | undefined
if ('data-rsc-css-href' in el.props) {
cssHref = el.props.href
}
if (cssHref && cssCollector) {
const cssHref =
'data-rsc-css-href' in el.props && typeof el.props.href === 'string'
? el.props.href
: undefined
if (cssHref && cssCollector) {
🤖 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-start-rsc/src/awaitLazyElements.ts` around lines 37 - 41, The
code assigns el.props.href (of any type) to cssHref and passes it to
cssCollector without a runtime type check; update the logic in awaitLazyElements
(the block using cssHref, cssCollector and the 'data-rsc-css-href' prop) to
verify typeof el.props.href === 'string' before assigning to cssHref or invoking
cssCollector, ensuring cssHref remains a string | undefined and only string
values are passed into CssHrefCollector; keep the existing conditional flow
('data-rsc-css-href' in el.props then cssHref && cssCollector) but add the
runtime typeof guard to satisfy strict TypeScript safety.

Comment on lines +154 to +157
async function createFromReadableStreamCollectingClientPreloads<T = unknown>(
stream: ReadableStream<Uint8Array>,
options?: object,
): Promise<T> {
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.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Confirm weakly typed options signature in this file.
rg -n 'options\\?: object' packages/react-start-rsc/src/rsbuild/ssr-decode.ts

Repository: TanStack/router

Length of output: 41


🏁 Script executed:

cat -n packages/react-start-rsc/src/rsbuild/ssr-decode.ts | sed -n '150,160p'

Repository: TanStack/router

Length of output: 480


🏁 Script executed:

rg -n 'createFromReadableStream' packages/react-start-rsc/src/rsbuild/ssr-decode.ts -A 2 -B 2

Repository: TanStack/router

Length of output: 755


🏁 Script executed:

rg -A 20 '"react-server-dom-rspack"' packages/react-start-rsc/package.json

Repository: TanStack/router

Length of output: 529


🏁 Script executed:

cat -n packages/react-start-rsc/tsconfig.json | head -20

Repository: TanStack/router

Length of output: 322


🏁 Script executed:

cat -n tsconfig.json | head -30

Repository: TanStack/router

Length of output: 1043


🏁 Script executed:

rg -n 'createFromReadableStream' packages/react-start-rsc/src/rsbuild/ssr-decode.ts -B 5 -A 5

Repository: TanStack/router

Length of output: 1273


Use the upstream decoder options type instead of object.

Line 156 uses weak typing that violates the strict mode requirement. The options parameter should be typed from the upstream createFromReadableStream signature to maintain type safety consistency with react-server-dom-rspack.

Proposed fix
 async function createFromReadableStreamCollectingClientPreloads<T = unknown>(
   stream: ReadableStream<Uint8Array>,
-  options?: object,
+  options?: Parameters<typeof createFromReadableStream>[1],
 ): Promise<T> {
🤖 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-start-rsc/src/rsbuild/ssr-decode.ts` around lines 154 - 157,
The options parameter in createFromReadableStreamCollectingClientPreloads is
weakly typed as object; replace it with the upstream decoder options type used
by react-server-dom-rspack (import the exact options type from the upstream
createFromReadableStream signature) and use that type for the options parameter
and any related variables so the function matches the upstream API (function
name: createFromReadableStreamCollectingClientPreloads; reference the
createFromReadableStream signature/type from react-server-dom-rspack to import
the correct type and update usages accordingly).

Comment on lines +178 to +180
const result = await createFromReadableStream<T>(decodeStream, options)
await preloadPromise
return result
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.

⚠️ Potential issue | 🟠 Major | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the wrapper has no try/finally around decode + preloadPromise.
rg -n -C4 'async function createFromReadableStreamCollectingClientPreloads|await createFromReadableStream|await preloadPromise|try|finally|catch' packages/react-start-rsc/src/rsbuild/ssr-decode.ts

Repository: TanStack/router

Length of output: 1510


🏁 Script executed:

sed -n '154,181p' packages/react-start-rsc/src/rsbuild/ssr-decode.ts

Repository: TanStack/router

Length of output: 1035


🏁 Script executed:

rg -n 'function createFromReadableStream|export.*createFromReadableStream' packages/react-start-rsc/src/rsbuild/ssr-decode.ts -A5

Repository: TanStack/router

Length of output: 269


🏁 Script executed:

head -30 packages/react-start-rsc/src/rsbuild/ssr-decode.ts

Repository: TanStack/router

Length of output: 641


🏁 Script executed:

rg -n 'createFromReadableStream' packages/react-start-rsc/src/rsbuild/ssr-decode.ts -B2 -A2

Repository: TanStack/router

Length of output: 755


🏁 Script executed:

rg -n 'options' packages/react-start-rsc/src/rsbuild/ssr-decode.ts | head -20

Repository: TanStack/router

Length of output: 221


🏁 Script executed:

rg -n 'react-server-dom-rspack' packages/react-start-rsc/src/rsbuild/ -B2 -A2

Repository: TanStack/router

Length of output: 708


🏁 Script executed:

fd -t f '*.d.ts|*.ts' packages/react-start-rsc/src/ | xargs rg -l 'react-server-dom-rspack' | head -5

Repository: TanStack/router

Length of output: 581


🏁 Script executed:

rg -n 'collectClientReferencePreloads' packages/react-start-rsc/src/rsbuild/ssr-decode.ts -B3 -A10

Repository: TanStack/router

Length of output: 888


Ensure preload scanner promise is always observed to prevent unhandled rejections.

If createFromReadableStream throws at line 178, the preloadPromise from the concurrent stream scanner is never awaited. This can cause unhandled promise rejections in SSR contexts.

The proposed fix should always observe the preload promise, not just on decode failure:

Improved fix
  const result = await createFromReadableStream<T>(decodeStream, options)
- await preloadPromise
- return result
+ try {
+   return result
+ } finally {
+   // Always ensure scanner promise is observed, even if decode fails
+   await preloadPromise.catch(() => {})
+ }

Additionally, options?: object should use strict typing to match the upstream createFromReadableStream signature for type safety consistency.

🤖 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-start-rsc/src/rsbuild/ssr-decode.ts` around lines 178 - 180,
If createFromReadableStream<T>(decodeStream, options) throws, preloadPromise
from the concurrent stream scanner is never awaited which can produce unhandled
rejections; always observe (await or attach a .catch) to preloadPromise
irrespective of success or failure of createFromReadableStream so the scanner's
promise is always settled (e.g., wrap the createFromReadableStream call in
try/finally and await preloadPromise in the finally block or add
preloadPromise.catch(() => {}) before returning/throwing). Also tighten the type
of options (replace the loose options?: object with the exact upstream signature
used by createFromReadableStream) so the function signature matches upstream and
preserves type safety.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants