fix: avoid buffering RSC payloads via unused tee branches in renderHTML#162
Merged
Conversation
renderHTML unconditionally teed the incoming RSC stream, but the second branch was only consumed in dev when no clientRscStream was provided. In build mode and in dev non-SSR mode the unread tee branch caused the stream implementation to buffer the entire RSC payload in memory (per entry during builds). Now the stream is only teed when the inline injection branch will actually be consumed. Closes #146 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01HMVhUo2qQedCq79R4Ks6zh
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.
Closes #146
Problem
renderHTMLinpackages/static/src/ssr/entry.tsxunconditionally teed the incoming RSC stream, but the second branch was only consumed in dev mode when noclientRscStreamwas provided. In two cases the branch was never read or cancelled:options.build === true): the payload injection step is skipped entirely;clientRscStreamprovided): the shell stream's second branch was unused.An unread
tee()branch causes the stream implementation to queue every chunk for it without bound, so the entire RSC payload was buffered in memory per render (per entry during builds).Fix
Only tee the stream when the inline injection branch will actually be consumed (dev mode without a separate
clientRscStream). Otherwise the original stream is passed directly tocreateFromReadableStream, and the injected stream (if any) is the caller-providedclientRscStream.Testing
pnpm typecheck,pnpm lint,pnpm test:run— all passpnpm test:e2e(31 tests) andpnpm test:e2e:dev(28 tests) — all pass, covering build+SSR, build+no-SSR, and both dev modes🤖 Generated with Claude Code
https://claude.ai/code/session_01HMVhUo2qQedCq79R4Ks6zh
Generated by Claude Code