mirror of
https://github.com/cloudflare/vinext.git
synced 2026-05-09 08:25:34 +02:00
[PR #1015] [MERGED] refactor: extract instrumentation lazy init to server/instrumentation-runtime.ts #1019
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#1019
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/1015
Author: @NathanDrake2406
Created: 5/2/2026
Status: ✅ Merged
Merged: 5/2/2026
Merged by: @james-elicx
Base:
main← Head:pr/extract-instrumentation-lazy-init📝 Commits (1)
40384c9refactor: extract instrumentation lazy init to server/instrumentation-runtime.ts📊 Changes
4 files changed (+185 additions, -67 deletions)
View changed files
📝
packages/vinext/src/entries/app-rsc-entry.ts(+17 -34)➕
packages/vinext/src/server/instrumentation-runtime.ts(+76 -0)📝
tests/__snapshots__/entry-templates.test.ts.snap(+8 -33)📝
tests/instrumentation.test.ts(+84 -0)📄 Description
Testing Kimi2.6
Summary
Extracts the 25-line
__ensureInstrumentationblock from the generated App Router RSC entry into a normal, typed, unit-testable module:server/instrumentation-runtime.ts.Principle: Codegen should describe the app shape; normal modules should implement behavior.
What changed
Before
entries/app-rsc-entry.tsemitted ~25 lines of inline generated code for every App Router project that usesinstrumentation.ts:__instrumentationInitialized,__instrumentationInitPromise)async function __ensureInstrumentation()register()andonRequestErrorwiringVINEXT_PRERENDERshort-circuitThis is the canonical "imperative shell with mutable bookkeeping" pattern. Embedding it in a template string makes it untestable, hard to review, and easy to drift between dev/prod paths.
After
packages/vinext/src/server/instrumentation-runtime.tsexportsensureInstrumentationRegistered(instrumentationModule).await ensureInstrumentationRegistered(_instrumentation)— two lines instead of twenty-five.register/onRequestError.Why this matters
ensureInstrumentationRegisteredimport, fixes or additions to instrumentation behavior automatically apply everywhere.Next.js references
Next.js supports
instrumentation.tsvia aregister()hook called once at server startup, plus an optionalonRequestError()handler. The semantics we preserve:packages/next/src/server/dev/next-dev-server.tsonRequestErrorso the handler is reachable across module graphs — Next.js stores the hook on a shared instrumentation instance:packages/next/src/server/lib/instrumentation/internal-lifecycle.tsTest plan
All pass locally.
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.