Skip to content

refactor(app-router): extract app page dispatch#986

Draft
NathanDrake2406 wants to merge 1 commit intocloudflare:mainfrom
NathanDrake2406:nathan/extract-app-page-dispatch
Draft

refactor(app-router): extract app page dispatch#986
NathanDrake2406 wants to merge 1 commit intocloudflare:mainfrom
NathanDrake2406:nathan/extract-app-page-dispatch

Conversation

@NathanDrake2406
Copy link
Copy Markdown
Contributor

@NathanDrake2406 NathanDrake2406 commented Apr 30, 2026

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.ts with response-level behavior coverage for the new dispatch module:

  • production page cache HIT serves cached HTML instead of revalidating params or rendering
  • unsupported page methods return the method policy response instead of rendering
  • dynamicParams = false returns 404 for paths outside generated params
  • intercepted RSC source-route payloads preserve middleware status and headers

These 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:

Validation

  • 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.snap
  • vp test run tests/app-page-dispatch.test.ts
  • vp 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.ts
  • vp run knip --no-progress
  • Commit hook reran staged-file checks and Knip successfully.

Risk 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.

Copilot AI review requested due to automatic review settings April 30, 2026 05:26
@pkg-pr-new
Copy link
Copy Markdown

pkg-pr-new Bot commented Apr 30, 2026

Open in StackBlitz

npm i https://pkg.pr.new/vinext@986

commit: 1a713e6

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.
@NathanDrake2406 NathanDrake2406 force-pushed the nathan/extract-app-page-dispatch branch from 7832b64 to 1a713e6 Compare April 30, 2026 05:33
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

@NathanDrake2406 NathanDrake2406 marked this pull request as draft April 30, 2026 06:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants