mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
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#753
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/661
Author: @james-elicx
Created: 3/22/2026
Status: ✅ Merged
Merged: 3/23/2026
Merged by: @james-elicx
Base:
main← Head:fix/660-defer-clear-request-context📝 Commits (2)
5f5ac28fix: defer clearRequestContext() until HTML stream is fully consumed352ed07fix: guard against stream-cancelled crashes in tick-buffered transform and early-disconnect cleanup📊 Changes
6 files changed (+208 additions, -15 deletions)
View changed files
📝
packages/vinext/src/server/app-page-render.ts(+14 -4)📝
packages/vinext/src/server/app-page-stream.ts(+58 -2)📝
packages/vinext/src/server/app-ssr-stream.ts(+11 -5)📝
tests/app-page-boundary-render.test.ts(+2 -2)📝
tests/app-page-render.test.ts(+80 -0)📝
tests/app-page-stream.test.ts(+43 -2)📄 Description
Summary
headers()/cookies()throwing "can only be called from a Server Component" on warm (module-cached) requests in App Router pages.clearRequestContext()was called synchronously after receiving the RSC/SSR stream handle, before any Server Components had executed. The stream is lazy — components run while the HTTP layer pulls the response body.TransformStreamwhoseflush()defersclearRequestContext()until the last byte is consumed. Values that must be read now (getDraftModeCookieHeader,consumeDynamicUsage,getRequestCacheLife) are still captured eagerly.Affected files
packages/vinext/src/server/app-page-render.ts—renderAppPageLifecycle(): covers both the plain and ISR-cacheable HTML response pathspackages/vinext/src/server/app-page-stream.ts—renderAppPageHtmlResponse(): same race in the legacy/direct code pathTests
Regression tests were written first (red) to reproduce the race, then the fix was applied (green):
tests/app-page-render.test.ts— 2 new tests assertingclearRequestContextis not called before stream consumption, one for each HTML code path (plain and ISR-cacheable)tests/app-page-stream.test.ts— 1 new test forrenderAppPageHtmlResponse; existing test updated to reflect the correct deferred timingCloses #660
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.