HMR WebSocket fails - middlewareMode prevents Vite's WebSocket handler
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Tech stack
- typescript, vite
- Domain
- tooling
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.
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()
- Dominant language
- TypeScript
- Stars
- 175
- Forks
- 16
- Avg merge
- 3d 12h
- Merged PRs (30d)
- 6
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- No contributing guide
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.
More from marko-js/run
-
DEP0190: spawnServer passes args array with shell:true, triggering Node v26 deprecation warningOpen
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 35/100
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 38/100
Maintainers usually reply within 1 day
Similar issues
-
triage
Difficulty 1/5 Under an hour Newbie friendliness 90/100
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
mermaid-js/mermaid-live-editor#2053 ·
Maintainers usually reply within 1 day
-
factory
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
jessepollak/home#1455 ·
Maintainers usually reply within 1 day
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
lingdojo/kana-dojo#31227 · 1 comment · 5 reactions ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 92/100
appandflow/stim#1838 ·
Maintainers usually reply within 1 day