mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #1083] [MERGED] refactor(server): dedupe TextDecoder stream consumption #1080
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#1080
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/1083
Author: @james-elicx
Created: 5/5/2026
Status: ✅ Merged
Merged: 5/5/2026
Merged by: @james-elicx
Base:
main← Head:refactor/dedupe-textdecoder-stream📝 Commits (2)
df69ae4refactor(server): dedupe TextDecoder stream consumptiond9c7350refactor(server): address review feedback from #1083📊 Changes
8 files changed (+94 additions, -97 deletions)
View changed files
📝
packages/vinext/src/server/app-page-cache.ts(+3 -12)📝
packages/vinext/src/server/app-page-dispatch.ts(+2 -2)📝
packages/vinext/src/server/app-page-execution.ts(+0 -17)📝
packages/vinext/src/server/app-server-action-execution.ts(+4 -20)📝
packages/vinext/src/server/pages-node-compat.ts(+4 -22)📝
packages/vinext/src/server/pages-page-response.ts(+2 -21)➕
packages/vinext/src/utils/text-stream.ts(+76 -0)📝
tests/app-page-execution.test.ts(+3 -3)📄 Description
Summary
Follow-up to the dedupe round (#1058, #1069-#1081). Extracts the repeated
new TextDecoder()+ReadableStreamchunk-loop into two helpers inpackages/vinext/src/utils/text-stream.ts:readStreamAsText(stream)for the consume-to-single-string shapereadStreamAsTextWithLimit(stream, maxBytes, onLimitExceeded)for the size-limited shape (callback throws so each caller keeps its own error type)Files changed
Deduped:
packages/vinext/src/server/app-page-cache.ts(ISR HTML cache write)packages/vinext/src/server/pages-page-response.ts(recordStreamToStringremoved; was only called once)packages/vinext/src/server/app-server-action-execution.ts(readActionBodyWithLimit)packages/vinext/src/server/pages-node-compat.ts(readPagesRequestBodyWithLimit)New helper:
packages/vinext/src/utils/text-stream.tsIntentionally left inline
These five sites have load-bearing differences that don't fit either helper:
rsc-stream-hints.ts- line-bufferedTransformStreamwithcarryfor partial Flight linesapp-ssr-stream.ts(createRscEmbedTransform) - interleaves raw-byte accumulation withfixFlightHintsapp-ssr-stream.ts(createTickBufferedTransform) - HTML transform applyingfixPreloadAsshims/fetch-cache.ts- mixed string/Uint8Array stream, tee handling, customBodyTooLargeForCacheKeyError, decoder also reused for non-streamUint8ArraybodySo 4 of 9 sites cleanly deduped; 5 left alone. Pure refactor; no behaviour change at the deduped sites except a minor robustness improvement:
readStreamAsTextreleases the reader lock infinally(the inline copy inapp-page-cache.tsdid not). The streams there are wholly consumed and not reused, so this is observably equivalent.Test plan
pnpm vp test run tests/app-router.test.ts tests/pages-router.test.ts(508 tests pass; the only failure is a pre-existing flakyafterAllcleanup hook inPages Router allowedDevOrigins configthat does not run any deduped code path)pnpm fmt --writepnpm knip(clean)🤖 Generated with Claude Code
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.