[PR #289] [MERGED] fix(instrumentation): defer ssrLoadModule to post-middleware hook #448

Closed
opened 2026-05-06 12:39:51 +02:00 by BreizhHardware · 0 comments

📋 Pull Request Information

Original PR: https://github.com/cloudflare/vinext/pull/289
Author: @Divkix
Created: 3/6/2026
Status: Merged
Merged: 3/7/2026
Merged by: @southpolesteve

Base: mainHead: fix/instrumentation-crash-167


📝 Commits (4)

  • 31791be fix(instrumentation): defer ssrLoadModule call to post-middleware hook
  • 7e56c5f fix(instrumentation): address review comments on deferred ssrLoadModule
  • 2fd3ed5 test: address instrumentation review feedback
  • 27765db Merge branch 'cloudflare:main' into fix/instrumentation-crash-167

📊 Changes

2 files changed (+32 additions, -7 deletions)

View changed files

📝 packages/vinext/src/index.ts (+9 -7)
📝 tests/features.test.ts (+23 -0)

📄 Description

Summary

  • Fixes #167vite dev crashes immediately when a project has instrumentation.ts
  • Moves runInstrumentation() call from the configureServer body into the returned post-middleware function, where Vite's SSR environment transport channel is fully initialized
  • Adds 2 regression tests covering transport error handling and successful register() invocation

Root Cause

Vite 7's SSRCompatModuleRunner requires the SSR environment's transport channel before ssrLoadModule() can be called. During configureServer(), the channel isn't ready yet → TypeError: Cannot read properties of undefined (reading 'outsideEmitter').

Changes

File Change
packages/vinext/src/index.ts Move runInstrumentation from configureServer body into returned post-middleware function
tests/features.test.ts Add 2 regression tests for ssrLoadModule transport errors and register() invocation

Test plan

  • pnpm test — all 2204 tests pass (2 pre-existing failures in static-export/ecosystem unrelated to this change)
  • pnpm run typecheck — no new type errors
  • pnpm run test:e2e — no regressions
  • Manual: create a project with instrumentation.ts, run vite dev, confirm no crash

/bonk


🔄 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/289 **Author:** [@Divkix](https://github.com/Divkix) **Created:** 3/6/2026 **Status:** ✅ Merged **Merged:** 3/7/2026 **Merged by:** [@southpolesteve](https://github.com/southpolesteve) **Base:** `main` ← **Head:** `fix/instrumentation-crash-167` --- ### 📝 Commits (4) - [`31791be`](https://github.com/cloudflare/vinext/commit/31791be47f246803ac32a2d4b19dd104bd6ba0e3) fix(instrumentation): defer ssrLoadModule call to post-middleware hook - [`7e56c5f`](https://github.com/cloudflare/vinext/commit/7e56c5f3ff1728a88a25490f8bc240324debaee7) fix(instrumentation): address review comments on deferred ssrLoadModule - [`2fd3ed5`](https://github.com/cloudflare/vinext/commit/2fd3ed5659ef73665dce2c04124c76d9f99ddefe) test: address instrumentation review feedback - [`27765db`](https://github.com/cloudflare/vinext/commit/27765dbb143affaf2fb74c69ba48162687736c89) Merge branch 'cloudflare:main' into fix/instrumentation-crash-167 ### 📊 Changes **2 files changed** (+32 additions, -7 deletions) <details> <summary>View changed files</summary> 📝 `packages/vinext/src/index.ts` (+9 -7) 📝 `tests/features.test.ts` (+23 -0) </details> ### 📄 Description ## Summary - **Fixes #167** — `vite dev` crashes immediately when a project has `instrumentation.ts` - Moves `runInstrumentation()` call from the `configureServer` body into the returned post-middleware function, where Vite's SSR environment transport channel is fully initialized - Adds 2 regression tests covering transport error handling and successful `register()` invocation ## Root Cause Vite 7's `SSRCompatModuleRunner` requires the SSR environment's transport channel before `ssrLoadModule()` can be called. During `configureServer()`, the channel isn't ready yet → `TypeError: Cannot read properties of undefined (reading 'outsideEmitter')`. ## Changes | File | Change | |------|--------| | `packages/vinext/src/index.ts` | Move `runInstrumentation` from configureServer body into returned post-middleware function | | `tests/features.test.ts` | Add 2 regression tests for ssrLoadModule transport errors and register() invocation | ## Test plan - [x] `pnpm test` — all 2204 tests pass (2 pre-existing failures in static-export/ecosystem unrelated to this change) - [x] `pnpm run typecheck` — no new type errors - [x] `pnpm run test:e2e` — no regressions - [x] Manual: create a project with `instrumentation.ts`, run `vite dev`, confirm no crash /bonk --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
BreizhHardware 2026-05-06 12:39:51 +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#448
No description provided.