mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #748] [MERGED] refactor: extract route wiring from generated entry into typed runtime module #815
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#815
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/748
Author: @NathanDrake2406
Created: 4/2/2026
Status: ✅ Merged
Merged: 4/3/2026
Merged by: @james-elicx
Base:
main← Head:feat/layout-persistence-pr-2b📝 Commits (7)
7f4f8ebExtract app page route wiring helpersbe33773Fix app page error boundary serializationca40d05Fix client error boundary pathname resetbddda39Document Next.js error boundary verificationf7b35a0Address bonk review: edge case tests and readability nit175ae93Address second-round review: type honesty and test cleanup98174caAdd comment explaining template vs layout param asymmetry📊 Changes
6 files changed (+910 additions, -1606 deletions)
View changed files
📝
packages/vinext/src/entries/app-rsc-entry.ts(+34 -233)➕
packages/vinext/src/server/app-page-route-wiring.tsx(+337 -0)📝
packages/vinext/src/shims/error-boundary.tsx(+31 -4)📝
tests/__snapshots__/entry-templates.test.ts.snap(+180 -1334)➕
tests/app-page-route-wiring.test.ts(+175 -0)📝
tests/error-boundary.test.ts(+153 -35)📄 Description
Summary
Part of #726 (PR 2b). Moves boundary/layout/segment wiring logic out of the generated entry template (
app-rsc-entry.ts) into a typed runtime module (server/app-page-route-wiring.tsx). This follows the project's architectural guideline that generated entries should stay thin: codegen glue, not runtime logic.What moved
The generated
buildPageElement()function inapp-rsc-entry.tspreviously contained ~250 lines of inline logic for:LayoutSegmentProviderwith computedsegmentMapat each layout levelErrorBoundary,NotFoundBoundary, andSuspense(loading) at correct tree positionsAll of this is now in
packages/vinext/src/server/app-page-route-wiring.tsxas typed, unit-testable functions:buildAppPageRouteElement()createAppPageLayoutEntries()resolveAppPageChildSegments()[id], catch-all[...slug], optional[[...slug]])createAppPageTreePath()The generated entry now imports and calls
__buildAppPageRouteElement()instead of inlining the logic. Template snapshots updated accordingly, and the generated code is much shorter.ErrorBoundary pathname-based reset
ErrorBoundarynow resets error state on pathname changes, matching the existing pattern inNotFoundBoundary. This was identified as a required fix in #726 because the boundary instance persists at the same tree position across client navigations.Implementation details:
ErrorBoundaryis now a function wrapper that readsusePathname()and passes it toErrorBoundaryInner.getDerivedStateFromProps()clears the caught error when the pathname changes.getDerivedStateFromError()preserves the existingpreviousPathnameinstead of overwriting it, which avoids immediately clearing freshly caught client errors beforeerror.tsxcan render.Important scope note: this reset is pathname-based only. It does not reset on search-param-only navigations because
usePathname()does not include the query string.Why this matters for layout persistence
PR 2c ("The Switch") needs to restructure how the route wiring is built from a single nested tree to flat map entries with
Slotreferences. Having the wiring logic in a typed module instead of embedded in a template string means PR 2c can modifybuildAppPageRouteElement()directly with type safety, IDE support, and focused unit tests.Test plan
tests/app-page-route-wiring.test.ts— unit coverage for the extracted helpers (segment resolution, layout entries, tree paths)tests/error-boundary.test.ts— pathname reset coverage, including a regression test that caught the immediate-clear bug in the client error boundary state machinetests/entry-templates.test.ts— snapshot updated to verify generated entry delegates to the extracted helperRefs #726
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.