fix: support WebSocket upgrades in Vite dev server#3737
Open
bartlomieju wants to merge 2 commits intomainfrom
Open
fix: support WebSocket upgrades in Vite dev server#3737bartlomieju wants to merge 2 commits intomainfrom
bartlomieju wants to merge 2 commits intomainfrom
Conversation
WebSocket upgrade requests never reached Fresh handlers in dev mode because Vite's Connect-based server fires 'upgrade' events on the underlying http.Server rather than routing them through middleware. Fix by starting a Deno HTTP server on a random port alongside Vite and proxying upgrade requests to it via raw TCP socket forwarding. This allows Deno.upgradeWebSocket() to work natively. Fixes #3350 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
8bc3c1c to
1ac26e1
Compare
- Replace Buffer type with Uint8Array to fix CI type checking - Add onError handler to Deno.serve to suppress broken pipe errors - Add close event handlers on proxy sockets for clean teardown - Wrap destroy calls in try/catch to prevent cascading errors Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
Author
|
The second Once that Deno issue is resolved, this workaround can be replaced with a simple |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
upgradeevents on the underlyinghttp.Serverrather than routing them through middleware, soDeno.upgradeWebSocket()was never calledDeno.serve()on a random port alongside Vite and proxy upgrade requests to it via raw TCP socket forwarding, whereDeno.upgradeWebSocket()works natively/__vite_hmr,/__vite_ping) are excluded from proxyingTest plan
vite dev - websocket upgradeverifies echo via WebSocket in dev modeFixes #3350
🤖 Generated with Claude Code