Repository navigation
fix(vite): register service environments only after they are constructed - #4743
Conversation
`createServiceEnvironment` added the environment to `ctx._viteEnvs` before building it. When the env runner became ready in that window it announced the environment to the dev worker before its Vite transport existed, so the worker's first module runner invoke (`getBuiltins`) was dropped and the environment never recovered. Register it after construction, as `createNitroEnvironment` already does; the environment announces itself from `init()` once its transport exists. Resolves nitrojs#4638
|
@reedjosh is attempting to deploy a commit to the Nitro Team on Vercel. A member of the Team first needs to authorize it. |
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configuration
📒 Files selected for processing (5)
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configuration
📒 Files selected for processing (2)
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review. 📝 WalkthroughWalkthrough
ChangesService environment registration
Priority: ➖ Normal Estimated code review effort: 2 (Simple) | ~10 minutes Change: Bug fix · Severity of issue fixed: Medium Merge Risk: ⚪ Minimal · up to The registration change is mergeable after normal checks. No startup failure from the changed ordering has been established. Security Architecture ReviewSecurity architecture risk: 🔵 Low · up to The change narrows a development startup race without changing the configured service entries or their execution permissions. Remaining uncertainty concerns initialization and shutdown ordering, not an identified new security exposure. Retained concerns Security review detailsSecurity Blast Radius
Trust Boundaries and Controls
Resilience and Maintainability Implications
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
…erver Replace the mocked unit test with a dev server test (real worker, real transport) where the dev worker's first invoke arrives before the ssr service environment is constructed. Without the fix the SSR request hangs; with it the page renders.
An environment registered in `_viteEnvs` after construction but before `init()` finished could still be announced by the runner's ready replay. The dev worker then invoked `fetchModule` before the plugin container existed and SSR kept failing. Register from `init()`, right before the environment announces itself, for both the nitro and service environments.
commit: |
🔗 Linked issue
Resolves #4638
❓ Type of change
📚 Description
When the env runner becomes ready, it replays every environment in
ctx._viteEnvsto the dev worker, and the worker starts importing from an environment as soon as it hears about it.createServiceEnvironmentadded its environment to that map before constructing it. That allowed two races on a coldvite devstart:getBuiltinsinvoke is dropped. SSR then stays unavailable for the life of the process (Vite environment "ssr" is unavailable, followed bytransport invoke timed out). This is the hang reported in vite dev:createServiceEnvironmentregistersssrin_viteEnvsbefore building it, so the dev worker's firstgetBuiltinsinvoke is dropped and SSR wedges permanently #4638.init(): the invoke handler exists, butfetchModulefails withpluginContainer called before initialized, and SSR returns 500.Both the nitro and service environments now register themselves (for the replay) and announce themselves only once
FetchableDevEnvironment.init()has finished.The new
test/vite/service-env-registration.test.tsstarts a real Vite dev server and forces each race by holding startup until the worker has invoked every environment it was told about. Both tests fail onmain, and pass with this change.🤖 Generated with AI assistant