Skip to content

SSR-enabled build renders each entry's tree twice #147

Description

@uhyo

Problem

In build() (packages/static/src/rsc/entry.tsx), when ssr is enabled, the identical element is rendered through two separate renderToReadableStream calls:

rootRscStream = renderToReadableStream<RscPayload>({ root: <Root>{appNode}</Root> });
appRscStream = renderToReadableStream<RscPayload>({ root: <Root>{appNode}</Root> });

Consequences:

  • every server component executes twice per entry (double data fetching / build work);
  • every defer() call runs twice, registering two registry entries whose payloads are both fully rendered; content-hashing later collapses the duplicates to the same output file, which hides the wasted work but doesn't avoid it.

Suggested fix

Render once and tee() the stream — one branch for renderHTML (SSR), one written as the app RSC payload. This halves build-time rendering and guarantees the two consumers see byte-identical streams.

Found during a framework audit.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions