Skip to content

fix(react-start-rsc): avoid pulling the router entry into the RSC bundle via start-server-core barrel import - #7938

Closed
FrancoKaddour wants to merge 1 commit into
TanStack:mainfrom
FrancoKaddour:fix/7934-rsc-barrel-import
Closed

fix(react-start-rsc): avoid pulling the router entry into the RSC bundle via start-server-core barrel import#7938
FrancoKaddour wants to merge 1 commit into
TanStack:mainfrom
FrancoKaddour:fix/7934-rsc-barrel-import

Conversation

@FrancoKaddour

@FrancoKaddour FrancoKaddour commented Aug 2, 2026

Copy link
Copy Markdown

Closes #7934

renderServerComponent and createCompositeComponent imported getRequest from the @tanstack/start-server-core root barrel. That barrel re-exports createStartHandler, which contains import('#tanstack-router-entry') / import('#tanstack-start-entry'). When either RSC helper enters the rsc environment graph (e.g. a server-fn file importing it — even unused, since @tanstack/react-start-rsc has no sideEffects: false), the dynamic router-entry import survives into the RSC build. Because the rsc environment gets the unpruned route tree, this emits a router-*.js chunk containing every route file — including server-only API routes and their heavy imports — duplicated from the SSR bundle (79 MB in the linked reproduction; exceeds Cloudflare Workers size limits).

Fix: import getRequest from the self-contained @tanstack/start-server-core/request-response subpath (the same subpath react-start/src/server.rsc.ts already re-exports for the RSC context), so createStartHandler and its router-entry dynamic import never enter the RSC module graph.

Verification

Verified against the issue reproduction (https://github.com/jeremy-code/tanstack-rsc-api-routes): a baseline build emits dist/server/rsc/assets/router-*.js at 76 MB (153 MB total dist). Applying this same two-import change to the installed @tanstack/react-start-rsc dist and rebuilding, the router chunk is no longer emitted and total dist drops to 78 MB. Unit tests (61) and the package build pass locally.

Summary by CodeRabbit

  • Bug Fixes

    • Improved React Server Component bundle generation by preventing unnecessary server-route dependencies from being included.
    • Reduced the risk of duplicated dependencies in generated RSC bundles.
  • Chores

    • Updated internal request handling imports without changing runtime behavior.

…dle via start-server-core barrel import

renderServerComponent and createCompositeComponent imported getRequest from
the @tanstack/start-server-core root barrel. That barrel re-exports
createStartHandler, which contains import('#tanstack-router-entry') /
import('#tanstack-start-entry'). When either RSC helper enters the rsc
environment graph (a server-fn file importing it is enough — even unused,
since react-start-rsc has no sideEffects:false), the dynamic router-entry
import survives into the RSC build. Because the rsc environment gets the
unpruned route tree, this emits a router-*.js chunk containing every route
file — including server-only API routes and their heavy imports — duplicated
from the SSR bundle (79 MB in the issue reproduction; exceeds Cloudflare
Workers size limits).

Import getRequest from the self-contained
@tanstack/start-server-core/request-response subpath instead (the same subpath
react-start/src/server.rsc.ts already re-exports for the RSC context), so
createStartHandler and its router-entry dynamic import never enter the RSC
module graph.

Closes TanStack#7934
@coderabbitai

coderabbitai Bot commented Aug 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 496a56be-0b3a-4489-a0b0-6002547c20f9

📥 Commits

Reviewing files that changed from the base of the PR and between 2cb221c and 0d54160.

📒 Files selected for processing (3)
  • .changeset/fix-rsc-barrel-import-leak.md
  • packages/react-start-rsc/src/createCompositeComponent.ts
  • packages/react-start-rsc/src/renderServerComponent.ts

📝 Walkthrough

Walkthrough

The RSC helper modules now import getRequest from @tanstack/start-server-core/request-response. A patch changeset documents the import-path correction for @tanstack/react-start-rsc.

Changes

RSC import isolation

Layer / File(s) Summary
Request-response subpath imports
packages/react-start-rsc/src/createCompositeComponent.ts, packages/react-start-rsc/src/renderServerComponent.ts, .changeset/fix-rsc-barrel-import-leak.md
Both RSC helpers use the dedicated request-response import path. The changeset records the patch release.

Estimated code review effort: 1 (Trivial) | ~5 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly identifies the import change and its purpose of preventing router code from entering the RSC bundle.
Linked Issues check ✅ Passed The import changes directly address issue #7934 by preventing server-route dependencies from entering the RSC bundle.
Out of Scope Changes check ✅ Passed The changeset and two import updates are limited to the linked issue's scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@FrancoKaddour
FrancoKaddour marked this pull request as ready for review August 3, 2026 12:30
schiller-manuel added a commit that referenced this pull request Aug 3, 2026
Use the Start storage context for request cancellation and focused server entrypoints to keep unrelated route dependencies out of the RSC module graph. Add emitted-build regression coverage for the boundary.

fixes #7938
@FrancoKaddour

Copy link
Copy Markdown
Author

Thanks @schiller-manuel#7944 is the comprehensive version of this: same two-import change at the core, plus the focused server entrypoints, the emitted-build regression coverage and the eslint guard that this PR didn't have. Glad the analysis was useful, and nice touch keeping the boundary enforced going forward.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Imported packages used in server routes are leaked/duplicated to RSC bundle when importing renderServerComponent/createCompositeComponent

1 participant