mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #1017] [MERGED] refactor(app-rsc-entry): delegate pure helpers to typed server modules #1021
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#1021
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/1017
Author: @NathanDrake2406
Created: 5/2/2026
Status: ✅ Merged
Merged: 5/3/2026
Merged by: @james-elicx
Base:
main← Head:refactor/extract-entry-helpers📝 Commits (5)
877eda3refactor(app-rsc-entry): delegate pure helpers to typed server modulesb09e7d6fix: remove redundant as cast and fix test module cachingaaea32ffix: resolve entry helper rebase conflictsb8b4cf2ci: rerun checks (font-google flake)df196bcUpdate packages/vinext/src/entries/app-rsc-entry.ts📊 Changes
13 files changed (+608 additions, -86 deletions)
View changed files
📝
knip.ts(+5 -0)📝
packages/vinext/src/entries/app-rsc-entry.ts(+33 -86)➕
packages/vinext/src/server/app-hook-warning-suppression.ts(+14 -0)➕
packages/vinext/src/server/app-post-middleware-context.ts(+25 -0)➕
packages/vinext/src/server/app-request-context.ts(+30 -0)➕
packages/vinext/src/server/app-rsc-error-handler.ts(+38 -0)📝
packages/vinext/src/server/rsc-stream-hints.ts(+6 -0)➕
tests/app-hook-warning-suppression.test.ts(+87 -0)➕
tests/app-post-middleware-context.test.ts(+91 -0)➕
tests/app-request-context.test.ts(+101 -0)📝
tests/app-router.test.ts(+61 -0)➕
tests/app-rsc-error-handler.test.ts(+107 -0)📝
tests/entry-templates.test.ts(+10 -0)📄 Description
Deepseek V4 Pro Max
What this changes
Extracts five inline runtime helpers from the generated App Router RSC entry template into dedicated typed modules under
packages/vinext/src/server/. The generated entry now imports and wires these helpers instead of owning their implementation.Why
The generated RSC entry template (
entries/app-rsc-entry.ts) contained five inline implementations of pure runtime behavior inside the template string. These inline blocks:AGENTS.md: "Generated Entry Modules Should Stay Thin")Approach
Five new or enhanced typed modules, each with focused unit tests:
__buildPostMwRequestContext(request)server/app-post-middleware-context.ts—buildPostMwRequestContext()createRscOnErrorHandler(request, pathname, routePath)server/app-rsc-error-handler.ts—createAppRscOnErrorHandler()__clearRequestContext()+setNavigationContext()server/app-request-context.ts—clearAppRequestContext()+setAppNavigationContext()renderToReadableStreampreload hint wrapperserver/rsc-stream-hints.ts—createRscRenderer()factoryconsole.errorhook warning patch + ALSserver/app-hook-warning-suppression.ts— side-effect importKey design decisions:
Aliased imports preserve call sites: The entry template aliases module exports so existing call sites need no changes. For example,
clearAppRequestContextis imported as__clearRequestContextso all 11 existing__clearRequestContext()calls remain valid.createAppRscOnErrorHandlertakesreportRequestErroras an explicit first parameter rather than capturing it from scope, making the factory pure and testable without mocking module imports.Hook warning suppression is imported as a side-effect module — the
console.errorpatch runs once at module evaluation time, matching the existing behavior. The entry template only imports the ALS handle (suppressHookWarningAls) for per-route suppression.createRscRendereris a pure factory that takes the rawrenderToReadableStreamimport and returns a wrapped version with preload hint normalization. This replaces the inlinefunction renderToReadableStream(model, options) { ... }wrapper.Removed unused imports from the template string:
AsyncLocalStorage,setHeadersContext,getHeadersContext,normalizeHost,_setNavigationContextOrig. These were only needed by the removed inline code.Reference architecture: this extends the pattern established by
server/app-rsc-errors.ts,server/app-rsc-route-matching.ts, andserver/app-page-dispatch.ts, which were already extracted from the same template. SeeAGENTS.mdsection "Generated Entry Modules Should Stay Thin."Validation
Risks / follow-ups
app-browser-entry.ts,app-ssr-entry.ts,pages-server-entry.ts) may benefit from the same extraction pattern in future PRscreateRscRendereris only consumed by the generated entry template string, so it appears unused to static analysis (handled via knip config exception)🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.