[PR #999] [CLOSED] refactor: introduce createAppRscHandler #1013

Closed
opened 2026-05-06 13:11:34 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/999
Author: @NathanDrake2406
Created: 5/1/2026
Status: Closed

Base: mainHead: nathan/create-app-rsc-handler


📝 Commits (2)

  • 817505c chore: rerun ci
  • db09233 refactor: introduce createAppRscHandler

📊 Changes

6 files changed (+2858 additions, -3851 deletions)

View changed files

📝 packages/vinext/src/entries/app-rsc-entry.ts (+308 -603)
packages/vinext/src/server/app-rsc-handler.ts (+556 -0)
📝 tests/__snapshots__/entry-templates.test.ts.snap (+1773 -3102)
📝 tests/app-router.test.ts (+98 -134)
tests/app-rsc-handler.test.ts (+104 -0)
📝 tests/entry-templates.test.ts (+19 -12)

📄 Description

Summary

This is stacked on #986

This introduces createAppRscHandler() and moves the top-level App Router RSC request lifecycle out of the generated entry and into a normal typed runtime module.

The generated entry now stays focused on app shape:

  • route/module imports
  • generated manifests and route maps
  • thin closures that describe how to dispatch matched pages, route handlers, and server actions

The runtime helper now owns request behavior:

  • dev origin checks and unified request context setup
  • basePath / trailing-slash normalization
  • prerender endpoints
  • config redirects and rewrites
  • middleware sequencing
  • metadata and public file dispatch
  • server action handoff
  • pages fallback / not-found fallback
  • post-response next.config.js header application

I also trimmed dead surface from the new seam by removing top-level handler options that were not actually consumed there (allowedOrigins, maxActionBodySize). Those remain owned by the action helpers, which is a better fit for the “codegen describes shape, normal modules implement behavior” split.

Why

app-rsc-entry.ts had accumulated too much request orchestration. That made the generated output harder to reason about, harder to test directly, and too easy to grow in the wrong direction.

This refactor keeps codegen responsible for describing the app-specific graph while moving stable behavior into importable runtime code with focused tests.

That layering is closer to how Next.js is structured:

Tests

  • vp check packages/vinext/src/entries/app-rsc-entry.ts packages/vinext/src/server/app-rsc-handler.ts tests/app-rsc-handler.test.ts tests/app-router.test.ts tests/entry-templates.test.ts
  • vp test run tests/entry-templates.test.ts -u
  • vp test run tests/app-rsc-handler.test.ts 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

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/cloudflare/vinext/pull/999 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 5/1/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `nathan/create-app-rsc-handler` --- ### 📝 Commits (2) - [`817505c`](https://github.com/cloudflare/vinext/commit/817505cc37371d442b25a5f85473660624208591) chore: rerun ci - [`db09233`](https://github.com/cloudflare/vinext/commit/db092330443d8dd5867e002769f7ecd28a1ef8f4) refactor: introduce createAppRscHandler ### 📊 Changes **6 files changed** (+2858 additions, -3851 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/entries/app-rsc-entry.ts` (+308 -603) ➕ `packages/vinext/src/server/app-rsc-handler.ts` (+556 -0) 📝 `tests/__snapshots__/entry-templates.test.ts.snap` (+1773 -3102) 📝 `tests/app-router.test.ts` (+98 -134) ➕ `tests/app-rsc-handler.test.ts` (+104 -0) 📝 `tests/entry-templates.test.ts` (+19 -12) </details> ### 📄 Description ## Summary This is stacked on #986 This introduces `createAppRscHandler()` and moves the top-level App Router RSC request lifecycle out of the generated entry and into a normal typed runtime module. The generated entry now stays focused on app shape: - route/module imports - generated manifests and route maps - thin closures that describe how to dispatch matched pages, route handlers, and server actions The runtime helper now owns request behavior: - dev origin checks and unified request context setup - basePath / trailing-slash normalization - prerender endpoints - config redirects and rewrites - middleware sequencing - metadata and public file dispatch - server action handoff - pages fallback / not-found fallback - post-response `next.config.js` header application I also trimmed dead surface from the new seam by removing top-level handler options that were not actually consumed there (`allowedOrigins`, `maxActionBodySize`). Those remain owned by the action helpers, which is a better fit for the “codegen describes shape, normal modules implement behavior” split. ## Why `app-rsc-entry.ts` had accumulated too much request orchestration. That made the generated output harder to reason about, harder to test directly, and too easy to grow in the wrong direction. This refactor keeps codegen responsible for describing the app-specific graph while moving stable behavior into importable runtime code with focused tests. That layering is closer to how Next.js is structured: - the template builds the route module shape: [packages/next/src/build/templates/app-page.ts#L126-L142](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/templates/app-page.ts#L126-L142) - the route module exposes the runtime boundary and delegates to rendering logic: [packages/next/src/server/route-modules/app-page/module.ts#L85-L169](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/route-modules/app-page/module.ts#L85-L169) - request/render orchestration lives in normal runtime code, not the template: [packages/next/src/server/app-render/app-render.tsx#L2568-L3063](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/app-render.tsx#L2568-L3063) - the exported render entrypoint is a thin boundary over that runtime: [packages/next/src/server/app-render/app-render.tsx#L3077-L3095](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/app-render.tsx#L3077-L3095) ## Tests - `vp check packages/vinext/src/entries/app-rsc-entry.ts packages/vinext/src/server/app-rsc-handler.ts tests/app-rsc-handler.test.ts tests/app-router.test.ts tests/entry-templates.test.ts` - `vp test run tests/entry-templates.test.ts -u` - `vp test run tests/app-rsc-handler.test.ts 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` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 13:11:34 +02:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/vinext#1013
No description provided.