mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #843] [MERGED] chore(debug): classification reasons sidecar behind VINEXT_DEBUG_CLASSIFICATION [6/6] #892
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#892
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/843
Author: @NathanDrake2406
Created: 4/14/2026
Status: ✅ Merged
Merged: 4/21/2026
Merged by: @james-elicx
Base:
main← Head:chore/pr-768-6-classification-debug-reasons📝 Commits (2)
f33d77bchore(debug): add classification reasons sidecar behind VINEXT_DEBUG_CLASSIFICATIONdcab0c5test(debug): cover runtime-probe error path and Layer 2 reasons dispatch📊 Changes
6 files changed (+539 additions, -3 deletions)
View changed files
📝
packages/vinext/src/entries/app-rsc-entry.ts(+22 -0)📝
packages/vinext/src/index.ts(+20 -0)📝
packages/vinext/src/server/app-page-execution.ts(+43 -0)📝
tests/__snapshots__/entry-templates.test.ts.snap(+150 -0)📝
tests/app-page-execution.test.ts(+174 -0)📝
tests/build-time-classification-integration.test.ts(+130 -3)📄 Description
Summary
PR 6 of 6, restack of #768. Previously stacked on #842; now rebased directly onto
mainafter #842 merged.Operators tracing why a layout was flagged static or dynamic can opt in with
VINEXT_DEBUG_CLASSIFICATION=1at build time. When active, the plugin patches a second stub (__VINEXT_CLASS_REASONS) with a dispatch table that returns per-layoutClassificationReasonstructures. The runtime probe loop emits a debug line per layout whendebugClassificationis wired, and the hot path remains allocation-free when debug is off because the stub returnsnull.The reasons machinery (types,
report.tstagged results, andbuildReasonsReplacement) already shipped in #842 as tested-but-uncalled infrastructure. This PR wires it up end-to-end.What changes
index.tsgenerateBundlehook readsVINEXT_DEBUG_CLASSIFICATIONat build time; when set, it callsbuildReasonsReplacementand patches the__VINEXT_CLASS_REASONSstub alongside__VINEXT_CLASS. Runs before the existingtarget.map = null/ manifest-clear so both inputs are still available.__VINEXT_CLASS_REASONSstub throws loudly, matching the existing policy for__VINEXT_CLASS.__VINEXT_CLASS_REASONSnull stub and an env-gated__classDebuglogger. Each route's__buildTimeReasonsfield is gated__classDebug ? __VINEXT_CLASS_REASONS(routeIdx) : null, so at module load the reasons Map is only constructed when runtime debug is also on.app-page-execution.tsaccepts optionalbuildTimeReasonsanddebugClassificationinLayoutClassificationOptions. The probe loop emits one debug line per layout across all three outcome paths: build-time classified, runtime probe success, runtime probe error. Theno-classifiervariant has a single documented producer here, the??fallback when a build-time classified layout has no attached reason payload.app-page-execution.test.ts; integration test asserts the__classDebuggating expression and the null stub when build-time debug is off.Combinations
Both env checks are independent and all four combinations are safe:
return null,__classDebugundefined, zero cost__classDebugundefined)return null, reasons map is null, fallback emits{ layer: "no-classifier" }Stack
Validation
Run locally via
vp test run <file>:tests/app-page-execution.test.ts(17 cases, including 3 new debug-gated cases)tests/build-time-classification-integration.test.ts(7 cases, including 2 new reasons-sidecar cases)tests/entry-templates.test.ts(snapshot regenerated)tests/app-router.test.tsvp checkcleanRisks / follow-ups
generateBundle+ string-replace pattern that @james-elicx flagged on #842 (https://github.com/cloudflare/vinext/pull/842#discussion_r3109733377). Each new dispatch table (here,__VINEXT_CLASS_REASONS) multiplies the regex surface and the drift detection surface. The feature itself is fine; the way it crosses the build boundary needs an upgrade. Tracked in #863, which scopes out a virtual-module-with-renderChunkreplacement that would fold both__VINEXT_CLASSand__VINEXT_CLASS_REASONSinto a single typed module contract. Landing that refactor before the next dispatch surface (render-time layout skip) avoids shipping a third parallel regex.VINEXT_DEBUG_CLASSIFICATIONis a literal in three sites (plugin, emitted codegen template, runtime type docblock). A rename requires grepping all three. Acceptable for a debug flag.classifyAllRouteLayoutstest-only divergence risk called out in #842 is unchanged by this PR.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.