mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #1018] [MERGED] refactor(app-router): extract buildPageElements into typed helper module #1022
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#1022
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/1018
Author: @NathanDrake2406
Created: 5/2/2026
Status: ✅ Merged
Merged: 5/2/2026
Merged by: @james-elicx
Base:
main← Head:extract/build-page-elements📝 Commits (2)
f4c2ec6refactor(app-router): extract buildPageElements into typed helper modulecaced88chore: register app-page-element-builder in knip entry list📊 Changes
8 files changed (+540 additions, -741 deletions)
View changed files
📝
knip.ts(+1 -0)📝
packages/vinext/src/entries/app-rsc-entry.ts(+11 -104)➕
packages/vinext/src/server/app-page-element-builder.ts(+188 -0)📝
packages/vinext/src/server/app-page-route-wiring.tsx(+2 -2)📝
tests/__snapshots__/entry-templates.test.ts.snap(+42 -624)➕
tests/app-page-element-builder.test.ts(+283 -0)📝
tests/app-router.test.ts(+4 -6)📝
tests/entry-templates.test.ts(+9 -5)📄 Description
What this changes
Extracts the
buildPageElementsfunction (the central element-construction path in the App Router RSC handler) from the generated entry template into a properly typed, independently testable module atserver/app-page-element-builder.ts.The generated entry now delegates to this module with a thin 12-line closure that passes per-app module references. No behavioural changes.
Why
The generated RSC entry template owned ~110 lines of orchestration logic inline: checking for page default exports, resolving page head metadata (including parallel route interception), building page React elements, and wiring everything into the nested layout + boundary tree via
buildAppPageElements.This had two problems:
Untestable directly. Any change to the element-construction path could only be verified through snapshot diffs of the generated output, not through behavioural assertions about what the function produces.
Violates the codegen principle. The generated entry should describe the app shape (route manifests, module references, thin wiring closures). Runtime behaviour — request/response orchestration, element tree construction, streaming — belongs in normal typed modules that can be reasoned about and tested independently.
Approach
server/app-page-element-builder.tswith fully typed options (BuildPageElementsOptions), a route shape (AppPageBuildRouteextending the existingAppPageRouteWiringRoute), and intercept typesAppPageErrorModuleandAppPageRouteWiringRoutefromapp-page-route-wiring.tsxso the new helper can reference them (previously local types)app-rsc-entry.ts) replaces the inline function body with a delegation:return __buildPageElements({ route, params, routePath, pageRequest, ...generatedModuleRefs })resolveAppPageHead,resolveActiveParallelRouteHeadInputs,markDynamicUsage,buildAppPageElements,createAppPageTreePath) from the generated entry templateNext.js source references
buildAppPageElements)resolveAppPageHead)Validation
tests/app-page-element-builder.test.ts— 9 focused unit tests covering:markDynamicUsagecall when search params have content (and absence when empty)matchedParamstests/entry-templates.test.ts— snapshot assertions updated to reflect the new delegation pattern (import, thin closure, absence of inlined helper logic)vp checkpasses with zero lint, format, or type errorsRisks / follow-ups
__interceptLayoutstest inapp-router.test.tswas updated to verify the delegation pattern instead of asserting on inlined helper imports that are now in the helper module.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.