mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #352] [MERGED] fix(app-router): don't clear RSC context before lazy stream is consumed #503
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#503
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/352
Author: @james-elicx
Created: 3/8/2026
Status: ✅ Merged
Merged: 3/8/2026
Merged by: @james-elicx
Base:
main← Head:j-branch-8📝 Commits (2)
c0a2435fix(app-router): don't clear RSC context before lazy stream is consumedaf053d6fix(app-router): remove premature context clears from server action and intercepting route RSC branches📊 Changes
5 files changed (+214 additions, -9 deletions)
View changed files
📝
packages/vinext/src/server/app-dev-server.ts(+21 -9)➕
tests/fixtures/app-basic/app/nextjs-compat/rsc-context-lazy-stream/layout.tsx(+28 -0)➕
tests/fixtures/app-basic/app/nextjs-compat/rsc-context-lazy-stream/not-found.tsx(+19 -0)➕
tests/fixtures/app-basic/app/nextjs-compat/rsc-context-lazy-stream/page.tsx(+15 -0)➕
tests/nextjs-compat/rsc-context-lazy-stream.test.ts(+131 -0)📄 Description
When handling RSC requests (client-side navigation), the handler was calling
setNavigationContext(null)andsetHeadersContext(null)immediately afterrenderToReadableStream()returned — before the stream was actually consumed.The problem:
renderToReadableStream()returns as soon as the shell is ready, but the stream is consumed lazily by the client. Async server components that run during stream consumption (e.g.NextIntlClientProviderServer, which is rendered as a child ofNextIntlClientProviderin a layout) would execute after the handler had already cleared context, causing them to see null headers/navigation context and throw. The symptom for users wasuseTranslations()failing with "context from NextIntlClientProvider was not found" during client-side navigation.Fix: Remove the early
setNavigationContext(null)/setHeadersContext(null)calls on the RSC response branches inrenderHTTPAccessFallbackPageandrenderErrorBoundaryPage. Context is already cleaned up correctly when theAsyncLocalStoragescope fromrunWithHeadersContextunwinds — no manual clear is needed.The HTML response branches are unaffected: those
awaitthe full SSR pipeline (handleSsr) before responding, so context is fully consumed by the time the clears run.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.