Skip to content

fix(vite): wait for environment registration before dispatching dev requests - #4703

Merged
pi0 merged 1 commit into
mainfrom
fix/vite-env-registration-race
Oct 3, 2026
Merged

pi0 merged 1 commit into
mainfrom
fix/vite-env-registration-race

Conversation

@pi0x

@pi0x pi0x commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Fixes a flaky Unknown vite environment "nitro" 500 in Vite dev, seen in test/presets/cloudflare-dev.test.ts (Vite mode).

The host registers each Vite environment with the dev worker through an IPC message (nitro:vite-env). IPC is not ordered with requests. With the miniflare runner, IPC goes over a WebSocket and requests go through dispatchFetch over HTTP. A request that arrives right after server.listen() can therefore reach fetch() before the worker has registered the environment.

Repro: run only the Vite-mode suite, pnpm vitest run test/presets/cloudflare-dev.test.ts -t vite. 12 of 15 runs failed locally. In the full file the Nitro-mode suite runs first and warms things up, which hides the race.

Fix: when a request targets an environment that is not registered yet, fetch() now waits for its registration. The wait is capped by the existing RELOAD_WAIT_TIMEOUT (30s). An environment that never registers still gets the same 500.

Tests: two cases added to test/unit/vite-dev-worker-reload.test.ts:

  • A request sent before registration gets the entry's response. This fails without the fix.
  • A request for an environment that never registers still fails with a 500 once the timeout passes.

After the fix, the Vite-mode stress loop passed 20 of 20 runs.

🤖 Generated with AI assistant

…equests

Env registrations reach the dev worker over IPC, which is not ordered with requests (workerd dispatches requests over HTTP and IPC over a WebSocket).
@pi0x
pi0x requested a review from pi0 as a code owner October 3, 2026 13:39
@vercel

vercel Bot commented Oct 3, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
nitro.build Ready Ready Preview Oct 3, 2026 1:39pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Navigate logical layers of code changes, visualize relationships, and explore their blast radius.

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: ae6df197-5d83-4b0a-824b-eb8e878a2059
📥 Commits

Reviewing files that changed from the base of the PR and between 4bcce9e and 28107a3.

📒 Files selected for processing (2)
  • src/runtime/internal/vite/dev-worker.mjs
  • test/unit/vite-dev-worker-reload.test.ts
 ___________________________________
< I like big bugs and I cannot lie. >
 -----------------------------------
  \
   \   \
        \ /\
        ( )
      .( o ).
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • Commit to this branch
  • Create a new PR
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@pkg-pr-new

pkg-pr-new Bot commented Oct 3, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/nitro@4703

commit: 28107a3

@vercel-internal-security-reviewer

Copy link
Copy Markdown

Security review details

@pi0
pi0 merged commit f6a593c into main Oct 3, 2026
14 of 15 checks passed
@pi0
pi0 deleted the fix/vite-env-registration-race branch October 3, 2026 13:42

This branch was successfully deployed

1 active deployment
Preview — 28107a33 Deployed Oct 3, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants