HMR WebSocket fails - middlewareMode prevents Vite's WebSocket handler
Nobody has claimed this yet.
- Dominant language
- TypeScript
- Stars
- 175
- Forks
- 17
- Avg merge
- 5h 26m
- Merged PRs (30d)
- 5
Description
Summary
HMR WebSocket connections fail when using marko-run dev. The WebSocket upgrade request returns 404 instead of 101 Switching Protocols.
Environment
@marko/run: 0.9.3vite: 7.2.2- Node.js: 20.x
Reproduce Steps
- Run
marko-run dev - Access the dev server through any proxy (Cloudflare Tunnel, nginx, etc.)
- Open browser DevTools → Network → WS filter
- Observe WebSocket returns 404, HMR doesn't work
Root Cause
In src/adapter/dev-server.ts:
server: { ...config?.server, middlewareMode: true }
Then in startDev:
const listener = devServer.middlewares.listen(port, ...);
The problem:
middlewareMode: truetells Vite NOT to create its own HTTP server (devServer.httpServerisnull)middlewares.listen()creates a NEW HTTP server- This new server doesn't have Vite's WebSocket upgrade handler attached
- WebSocket upgrades get routed as HTTP GET → 404
Proof
- Raw
npx vite→ WebSocket returns101 Switching Protocols✅ marko-run dev→ WebSocket returns404❌
Proposed Fix
// Don't use middlewareMode
server: { ...config?.server, middlewareMode: false }
// Use Vite's httpServer
devServer.httpServer.listen(port, ...);
Workaround
Users can use patch-package to patch node_modules/@marko/run/dist/adapter/index.js:
- Change
middlewareMode: truetofalse - Change
devServer.middlewares.listen()todevServer.httpServer.listen()
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/adapter/dev-server.ts, focusing on the server configuration and startDev entry point described in the issue. Reproduce the failure with marko-run dev through a proxy and compare its WebSocket setup with raw Vite. Done means the proxied HMR connection receives 101 Switching Protocols instead of 404.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript, vite
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 55/100