Skip to content

Commit e5bc05b

Browse files
authored
fix: render SSR-enabled build entries once by teeing the RSC stream (#163)
1 parent 64c57d0 commit e5bc05b

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

packages/static/src/rsc/entry.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -293,13 +293,12 @@ export async function build() {
293293
let appRscStream: ReadableStream<Uint8Array>;
294294

295295
if (ssrEnabled) {
296-
// SSR on: both streams have full tree
297-
rootRscStream = renderToReadableStream<RscPayload>({
296+
// SSR on: render the full tree once and tee the stream — one branch
297+
// for SSR HTML, one for the app RSC payload. Rendering twice would
298+
// execute every server component (and defer()) twice per entry (#147).
299+
[rootRscStream, appRscStream] = renderToReadableStream<RscPayload>({
298300
root: <Root>{appNode}</Root>,
299-
});
300-
appRscStream = renderToReadableStream<RscPayload>({
301-
root: <Root>{appNode}</Root>,
302-
});
301+
}).tee();
303302
} else {
304303
// SSR off: root stream has shell, app stream has App only
305304
rootRscStream = renderToReadableStream<RscPayload>({

0 commit comments

Comments
 (0)