fix: render SSR-enabled build entries once by teeing the RSC stream#163
Merged
Conversation
When ssr is enabled, build() rendered the identical element through two separate renderToReadableStream calls — one for SSR HTML and one for the app RSC payload. Every server component (and defer() call) therefore executed twice per entry. Render once and tee() the stream instead, so both consumers see byte-identical streams with half the rendering work. Closes #147 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01ShuMmxpPtcxZrHMQZdbq2a
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #147.
When
ssris enabled,build()inpackages/static/src/rsc/entry.tsxrendered the identical element through two separaterenderToReadableStreamcalls — one stream fed torenderHTMLfor SSR, the other written as the app RSC payload. As a result:defer()call ran twice, registering duplicate registry entries whose payloads were both fully rendered (content hashing collapsed the duplicates to the same output file, hiding the waste but not avoiding it).Change
Render the full tree once and
tee()the resulting stream — one branch goes torenderHTMLfor SSR, the other becomes the app RSC payload. This halves build-time rendering per SSR entry and guarantees both consumers see byte-identical streams.The
tee()'d payload branch simply buffers whilerenderHTMLdrains the SSR branch; it is fully drained to a string shortly after inbuildApp.ts, so there is no unbounded-buffering concern at build time. The non-SSR path is unchanged (its two streams render genuinely different trees). Dev-server rendering already used a single stream.Testing
pnpm buildandpnpm typecheckpasspnpm test:run— 102 unit tests passpnpm test:e2e— all 31 e2e tests pass, including thessr-defersuite which exercises SSR builds withdefer()🤖 Generated with Claude Code
https://claude.ai/code/session_01ShuMmxpPtcxZrHMQZdbq2a
Generated by Claude Code