refactor(app-router): extract app page dispatch#986
Draft
NathanDrake2406 wants to merge 1 commit intocloudflare:mainfrom
Draft
refactor(app-router): extract app page dispatch#986NathanDrake2406 wants to merge 1 commit intocloudflare:mainfrom
NathanDrake2406 wants to merge 1 commit intocloudflare:mainfrom
Conversation
commit: |
App Router page requests now enter a shared dispatch module after generated route matching. The generated RSC entry still describes route modules, app-shape callbacks, and request-local values, but cache reads, static generation context, dynamic param checks, intercept responses, and lifecycle rendering move into normal typed code. This keeps page orchestration out of codegen without changing the observable App Router behavior covered by the integration suite.
7832b64 to
1a713e6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changed
This extracts App Router page request orchestration out of the generated RSC entry and into
packages/vinext/src/server/app-page-dispatch.ts.The generated entry now describes app shape and request wiring only: matched route, params, component tree builder, boundary render callbacks, middleware context, cache keys, and module loaders. The normal runtime module owns behavior: method policy, force-static/error setup, ISR cache read/regeneration, dynamic params validation, intercepting route responses, page element build error handling, lifecycle render delegation, and special-error fallback routing.
Why
This follows the principle that codegen should describe the app shape while normal modules implement behavior. The prior generated template mixed route-specific imports with a large page dispatch pipeline, which made orchestration harder to type, test, review, and evolve independently from route manifest generation.
Behavior tests
Added
tests/app-page-dispatch.test.tswith response-level behavior coverage for the new dispatch module:dynamicParams = falsereturns 404 for paths outside generated paramsThese tests assert HTTP-visible outcomes: status, headers, and response body. They avoid asserting dispatch call counts or generated implementation details.
Next.js references
Next.js uses a similar separation between generated app-page shape and runtime page rendering modules:
AppPageRouteModuleAppPageRouteModuleis the runtime module boundary for app page renderingAppPageRouteModule.render()delegates torenderToHTMLOrFlightrenderToHTMLOrFlightImplowns the app render orchestrationrenderToHTMLOrFlightexposes the stable runtime entrypointValidation
vp check --fix knip.ts packages/vinext/src/entries/app-rsc-entry.ts packages/vinext/src/server/app-page-dispatch.ts packages/vinext/src/server/app-page-request.ts tests/app-page-dispatch.test.ts tests/app-router.test.ts tests/entry-templates.test.ts tests/__snapshots__/entry-templates.test.ts.snapvp test run tests/app-page-dispatch.test.tsvp test run tests/app-page-dispatch.test.ts tests/entry-templates.test.ts tests/app-router.test.ts tests/app-page-render.test.ts tests/app-page-request.test.ts tests/app-page-cache.test.tsvp run knip --no-progressRisk coverage
Covered the main behavioral risks through dedicated dispatch behavior tests plus the App Router integration suite: dev/prod App Router rendering, RSC/HTML responses, ISR cache reads and writes, route handler separation, middleware header propagation, dynamic params validation, intercepting routes, not-found/forbidden/unauthorized boundaries, and generated-entry delegation assertions.
The generated-code tests intentionally assert only the delegation contract now. Runtime dispatch behavior is covered by
tests/app-page-dispatch.test.ts, existing helper tests, and the App Router integration suite.