mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #392] perf: tee stream for ISR caching instead of full re-render #536
Labels
No labels
enhancement
enhancement
good first issue
help wanted
nextjs-tracking
nextjs-tracking
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
starred/vinext#536
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/cloudflare/vinext/pull/392
Author: @james-elicx
Created: 3/9/2026
Status: 🔄 Open
Base:
main← Head:fix/isr-stream-tee-no-double-render📝 Commits (2)
438ac0dperf: tee stream for ISR caching instead of full re-renderd8a2275test: update Pages Router server entry snapshot for stream tee ISR change📊 Changes
3 files changed (+125 additions, -48 deletions)
View changed files
📝
packages/vinext/src/entries/pages-server-entry.ts(+28 -14)📝
packages/vinext/src/server/dev-server.ts(+69 -20)📝
tests/__snapshots__/entry-templates.test.ts.snap(+28 -14)📄 Description
Problem
On every ISR cache miss, both the dev server and the production pages entry were doing a complete second
renderToStringAsyncof the page purely to get an HTML string for the cache. The HTML produced by the first streaming render was thrown away.Same pattern existed in
pages-server-entry.tswith an explicit comment acknowledging the trade-off.Fix
Use
ReadableStream.tee()to split the body stream at render time. One branch streams to the client; the other is collected for the cache. No second render.dev-server.tsstreamPageToResponse()gains acollectHtmloption. When set, it tees thebodyStream, pipes one branch to the Node.js response as before, drains the other into a string, and returnsprefix + body + suffixto the caller. The ISR block now just callsisrSetwith that returned string.pages-server-entry.ts(production / Cloudflare Workers)The
compositeStream(already a full-document stream: shell prefix + body + shell suffix) is teed before theResponseis returned. The cache branch is consumed in a background async IIFE — it does not block the streaming response to the client.Result
collectHtmldefaults tofalse)Testing
tests/pages-router.test.tstests passtests/isr-cache.test.tstests pass🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.