[PR #1097] perf(prerender): reuse embedded RSC payload #1093

Open
opened 2026-05-06 13:11:57 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/1097
Author: @NathanDrake2406
Created: 5/6/2026
Status: 🔄 Open

Base: mainHead: nathan/prerender-rsc-dedupe


📝 Commits (5)

  • 556ca94 perf(prerender): reuse embedded RSC payload
  • 8810def fix(prerender): address RSC extraction review
  • d723196 Merge remote-tracking branch 'upstream/main' into nathan/prerender-rsc-dedupe
  • b889c28 fix(test): include artifact compatibility metadata
  • ae5d956 fix(prerender): document RSC extraction invariants

📊 Changes

3 files changed (+447 additions, -9 deletions)

View changed files

📝 packages/vinext/src/build/prerender.ts (+189 -9)
📝 tests/app-elements.test.ts (+1 -0)
📝 tests/prerender.test.ts (+257 -0)

📄 Description

What this changes

App Router prerender now reconstructs the canonical .rsc payload from the RSC bootstrap scripts already embedded in the prerendered HTML response when that protocol is present. Successful extraction avoids the previous second RSC: 1 handler invocation.

Why

The prerender pipeline already renders HTML first, and that HTML includes streamed Flight chunks for hydration. Issuing a second App Router RSC request duplicates work and can repeat expensive route rendering during build output generation.

Approach

  • Parse the prerendered HTML for Vinext streamed RSC chunk scripts and the completion marker, preserving chunk order and the existing HTML-safe JSON encoding semantics.
  • Support the legacy self.__VINEXT_RSC__={ rsc: [...] } embedded payload shape.
  • Keep an explicit compatibility fallback to the separate RSC request only when no recognized Vinext RSC embed markers exist.
  • Treat malformed or incomplete recognized embeds as errors instead of silently falling back.

Validation

  • vp test run tests/prerender.test.ts -t "extractRscPayloadFromPrerenderedHtml|writes the .rsc file from rendered HTML|prerenderApp — default mode"
  • vp check tests/prerender.test.ts
  • Commit hook vp check --fix plus knip --no-progress

Risks / follow-ups

  • The extractor intentionally matches Vinext's current inline RSC script protocol. If the emitter changes, the extraction tests should change with it.
  • Full test suite was not run locally.

Refs #563


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/1097 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 5/6/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `nathan/prerender-rsc-dedupe` --- ### 📝 Commits (5) - [`556ca94`](https://github.com/cloudflare/vinext/commit/556ca947c2fe19118bb8f7bddf5c8c6e5e2af7e8) perf(prerender): reuse embedded RSC payload - [`8810def`](https://github.com/cloudflare/vinext/commit/8810def835abe434722fc0d0b3d7e1139cc1c640) fix(prerender): address RSC extraction review - [`d723196`](https://github.com/cloudflare/vinext/commit/d723196425558cbd5018f8867c3cb381d999cc2b) Merge remote-tracking branch 'upstream/main' into nathan/prerender-rsc-dedupe - [`b889c28`](https://github.com/cloudflare/vinext/commit/b889c280c20848856b1976e62054e78f5b19a34a) fix(test): include artifact compatibility metadata - [`ae5d956`](https://github.com/cloudflare/vinext/commit/ae5d9567e4793b34d103ac04f2d8491b238ee32d) fix(prerender): document RSC extraction invariants ### 📊 Changes **3 files changed** (+447 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/build/prerender.ts` (+189 -9) 📝 `tests/app-elements.test.ts` (+1 -0) 📝 `tests/prerender.test.ts` (+257 -0) </details> ### 📄 Description ## What this changes App Router prerender now reconstructs the canonical `.rsc` payload from the RSC bootstrap scripts already embedded in the prerendered HTML response when that protocol is present. Successful extraction avoids the previous second `RSC: 1` handler invocation. ## Why The prerender pipeline already renders HTML first, and that HTML includes streamed Flight chunks for hydration. Issuing a second App Router RSC request duplicates work and can repeat expensive route rendering during build output generation. ## Approach - Parse the prerendered HTML for Vinext streamed RSC chunk scripts and the completion marker, preserving chunk order and the existing HTML-safe JSON encoding semantics. - Support the legacy `self.__VINEXT_RSC__={ rsc: [...] }` embedded payload shape. - Keep an explicit compatibility fallback to the separate RSC request only when no recognized Vinext RSC embed markers exist. - Treat malformed or incomplete recognized embeds as errors instead of silently falling back. ## Validation - `vp test run tests/prerender.test.ts -t "extractRscPayloadFromPrerenderedHtml|writes the .rsc file from rendered HTML|prerenderApp — default mode"` - `vp check tests/prerender.test.ts` - Commit hook `vp check --fix` plus `knip --no-progress` ## Risks / follow-ups - The extractor intentionally matches Vinext's current inline RSC script protocol. If the emitter changes, the extraction tests should change with it. - Full test suite was not run locally. Refs #563 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#1093
No description provided.