fix(react-start-rsc): avoid pulling the router entry into the RSC bundle via start-server-core barrel import - #7938
Conversation
…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
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThe RSC helper modules now import ChangesRSC import isolation
Estimated code review effort: 1 (Trivial) | ~5 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
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
|
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. |
Closes #7934
renderServerComponentandcreateCompositeComponentimportedgetRequestfrom the@tanstack/start-server-coreroot barrel. That barrel re-exportscreateStartHandler, which containsimport('#tanstack-router-entry')/import('#tanstack-start-entry'). When either RSC helper enters therscenvironment graph (e.g. a server-fn file importing it — even unused, since@tanstack/react-start-rschas nosideEffects: false), the dynamic router-entry import survives into the RSC build. Because therscenvironment gets the unpruned route tree, this emits arouter-*.jschunk 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
getRequestfrom the self-contained@tanstack/start-server-core/request-responsesubpath (the same subpathreact-start/src/server.rsc.tsalready re-exports for the RSC context), socreateStartHandlerand 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-*.jsat 76 MB (153 MB total dist). Applying this same two-import change to the installed@tanstack/react-start-rscdist 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
Chores