[PR #997] [MERGED] refactor(build): move route classification injection behind a typed planner #1010

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

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/997
Author: @NathanDrake2406
Created: 5/1/2026
Status: Merged
Merged: 5/2/2026
Merged by: @james-elicx

Base: mainHead: nathan/build-classification-injector


📝 Commits (2)

  • e0645bd refactor(build): move route classification injection behind a typed planner
  • 6eee62e refactor(build): tighten classification stub validation

📊 Changes

3 files changed (+377 additions, -108 deletions)

View changed files

packages/vinext/src/build/route-classification-injector.ts (+168 -0)
📝 packages/vinext/src/index.ts (+28 -108)
tests/route-classification-injector.test.ts (+181 -0)

📄 Description

What this changes

Moves build-time route classification injection out of the Vite generateBundle hook and into a normal typed module. The hook now only adapts final RSC chunks and module info, then applies the patch plan returned by route-classification-injector.

This follows the project principle: codegen should describe the app shape; normal modules should implement behavior. The generated RSC entry still emits stable __VINEXT_CLASS and __VINEXT_CLASS_REASONS stubs plus per-route call sites. The new module owns drift detection, Layer 2 module-graph classification, Layer 1 priority, debug reason patching, and source-map invalidation.

Why

The previous hook mixed Vite shell concerns with classification behavior, so important edge cases were only practical to exercise through plugin integration builds. That made a compatibility-sensitive path harder to reason about and easier to regress when generated source shape, Rolldown output, or classification policy changes.

Relevant Next.js source context:

Approach

  • Add planRouteClassificationInjection() as the functional core for the final RSC classification patch.
  • Keep Vite-specific work in index.ts: gather chunks, adapt Rollup/Rolldown module info, apply the returned patch, and clear the consumed manifest.
  • Preserve existing behavior for scan-phase no-ops, missing stub drift errors, multiple stub errors, debug sidecar patching, Layer 1 priority over module graph results, and stale source-map invalidation.

Validation

  • vp test run tests/route-classification-injector.test.ts tests/route-classification-manifest.test.ts tests/build-time-classification-integration.test.ts
  • vp check packages/vinext/src/build/route-classification-injector.ts packages/vinext/src/index.ts tests/route-classification-injector.test.ts
  • vp run vinext#build

vp run vinext#build completed with the existing package-build unresolved virtual module warnings for virtual:vinext-rsc-entry, private-next-instrumentation-client, and virtual:vite-rsc/client-references.

Risks / follow-ups

This is intentionally scoped to classification injection. It does not change the generated RSC entry shape, route manifest collection, or runtime probe behavior.


🔄 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/997 **Author:** [@NathanDrake2406](https://github.com/NathanDrake2406) **Created:** 5/1/2026 **Status:** ✅ Merged **Merged:** 5/2/2026 **Merged by:** [@james-elicx](https://github.com/james-elicx) **Base:** `main` ← **Head:** `nathan/build-classification-injector` --- ### 📝 Commits (2) - [`e0645bd`](https://github.com/cloudflare/vinext/commit/e0645bdfd0d286693c168c6785717cc5ee254266) refactor(build): move route classification injection behind a typed planner - [`6eee62e`](https://github.com/cloudflare/vinext/commit/6eee62e820235d76f4aa891f2525a93f5e5b5f1a) refactor(build): tighten classification stub validation ### 📊 Changes **3 files changed** (+377 additions, -108 deletions) <details> <summary>View changed files</summary> ➕ `packages/vinext/src/build/route-classification-injector.ts` (+168 -0) 📝 `packages/vinext/src/index.ts` (+28 -108) ➕ `tests/route-classification-injector.test.ts` (+181 -0) </details> ### 📄 Description ## What this changes Moves build-time route classification injection out of the Vite `generateBundle` hook and into a normal typed module. The hook now only adapts final RSC chunks and module info, then applies the patch plan returned by `route-classification-injector`. This follows the project principle: codegen should describe the app shape; normal modules should implement behavior. The generated RSC entry still emits stable `__VINEXT_CLASS` and `__VINEXT_CLASS_REASONS` stubs plus per-route call sites. The new module owns drift detection, Layer 2 module-graph classification, Layer 1 priority, debug reason patching, and source-map invalidation. ## Why The previous hook mixed Vite shell concerns with classification behavior, so important edge cases were only practical to exercise through plugin integration builds. That made a compatibility-sensitive path harder to reason about and easier to regress when generated source shape, Rolldown output, or classification policy changes. Relevant Next.js source context: - [App segment config parsing](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/segment-config/app/app-segment-config.ts) - [App route segment collection](https://github.com/vercel/next.js/blob/canary/packages/next/src/build/segment-config/app/app-segments.ts) - [Runtime handling for `dynamic` and `revalidate` segment config](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/create-component-tree.tsx#L279-L360) - [Dynamic usage tracking during app rendering](https://github.com/vercel/next.js/blob/canary/packages/next/src/server/app-render/dynamic-rendering.ts) ## Approach - Add `planRouteClassificationInjection()` as the functional core for the final RSC classification patch. - Keep Vite-specific work in `index.ts`: gather chunks, adapt Rollup/Rolldown module info, apply the returned patch, and clear the consumed manifest. - Preserve existing behavior for scan-phase no-ops, missing stub drift errors, multiple stub errors, debug sidecar patching, Layer 1 priority over module graph results, and stale source-map invalidation. ## Validation - `vp test run tests/route-classification-injector.test.ts tests/route-classification-manifest.test.ts tests/build-time-classification-integration.test.ts` - `vp check packages/vinext/src/build/route-classification-injector.ts packages/vinext/src/index.ts tests/route-classification-injector.test.ts` - `vp run vinext#build` `vp run vinext#build` completed with the existing package-build unresolved virtual module warnings for `virtual:vinext-rsc-entry`, `private-next-instrumentation-client`, and `virtual:vite-rsc/client-references`. ## Risks / follow-ups This is intentionally scoped to classification injection. It does not change the generated RSC entry shape, route manifest collection, or runtime probe behavior. --- <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:32 +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#1010
No description provided.