Skip to content

fix(dev): use the websocket adapter of the runtime the dev worker runs in - #4711

Merged
pi0 merged 1 commit into
mainfrom
fix/dev-websocket-runtime-adapter
Oct 3, 2026
Merged

pi0 merged 1 commit into
mainfrom
fix/dev-websocket-runtime-adapter

Conversation

@pi0x

@pi0x pi0x commented Oct 3, 2026

Copy link
Copy Markdown
Contributor

WebSockets in dev only worked on Node: both dev entries (nitro dev and the Vite dev worker) imported crossws/adapters/node directly, so running under bun --bun crashed with [crossws] Using Node.js adapter in an incompatible environment.

The dev entries now export crossws { resolve } options through env-runner's websocket entry field, and env-runner installs the adapter of the runtime the worker actually runs in. The Vite worker entry only declares it when features.websocket is enabled, and resolving hooks now waits for the app entry, which also fixes a WebSocket sent as the very first request failing on Node.

test/vite/websocket.test.ts starts real dev servers in a child process and echoes over a WebSocket for Vite dev and nitro dev, under Node and bun --bun. Three of the four cases fail on main (nitro dev on Node already worked). nitro dev under Deno was checked by hand.

Combines #4376 and #4597. The parent dev server WebSocket proxy and the hook caching from #4376 are not needed: current Bun proxies the upgrade through node:http fine, and crossws 0.4.12 already caches resolved hooks per connection.

Fixes #3939

🤖 Generated with AI assistant

…s in

Supersedes #4376 and #4597.

Co-authored-by: productdevbook <hi@productdevbook.com>
@pi0x
pi0x requested a review from pi0 as a code owner October 3, 2026 14:32
@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 2:33pm 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: 19b59b3d-e065-45ea-9ed0-4f8a531b3324
📥 Commits

Reviewing files that changed from the base of the PR and between 87e338e and 6319a57.

📒 Files selected for processing (7)
  • src/build/vite/_dev-worker.ts
  • src/presets/_nitro/runtime/nitro-dev.ts
  • src/runtime/internal/vite/dev-entry.mjs
  • src/runtime/internal/vite/dev-worker.mjs
  • test/vite/websocket-fixture/routes/ws.ts
  • test/vite/websocket-fixture/vite.config.ts
  • test/vite/websocket.test.ts
 ___________________________________________________________________________________________________________________________________
< Finish what you start. Where possible, the routine or object that allocates a resource should be responsible for deallocating it. >
 -----------------------------------------------------------------------------------------------------------------------------------
  \
   \   (\__/)
       (•ㅅ•)
       /   づ
✨ 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@4711

commit: 6319a57

@pi0
pi0 merged commit 584d10a into main Oct 3, 2026
14 of 15 checks passed
@pi0
pi0 deleted the fix/dev-websocket-runtime-adapter branch October 3, 2026 14:36

This branch was successfully deployed

1 active deployment
Preview — 6319a57a 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.

Websocket does not work in vite dev mode with bun runtime

2 participants