fix(vite-plugin): preserve worker websocket service bindings in dev#13098
fix(vite-plugin): preserve worker websocket service bindings in dev#13098raashish1601 wants to merge 3 commits into
Conversation
🦋 Changeset detectedLatest commit: 4842265 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
Codeowners approval required for this PR:
Show detailed file reviewers
|
Upgrade requests (e.g. WebSocket) cannot be proxied through the Node.js middleware binding because the upgrade event provides a raw Duplex socket rather than an http.ServerResponse. Detect the Upgrade header in ViteProxyWorker and send these requests directly to the entry worker. Replaces the original unit test and playground regression with a dev-registry fixture test that exercises the actual cross-process path (vite dev <-> vite dev via the dev registry).
f1cb50c to
4842265
Compare
create-cloudflare
@cloudflare/kv-asset-handler
miniflare
@cloudflare/pages-shared
@cloudflare/unenv-preset
@cloudflare/vite-plugin
@cloudflare/vitest-pool-workers
@cloudflare/workers-editor-shared
wrangler
commit: |
|
Hi @raashish1601. Thanks for the PR and for fixing the issue! There are just some formatting issues so please can you run |
|
Just wondering if this PR will solve my usecase:
web wrangler file: Running locally using I have a feeling this is also related to the web app not being able to properly resolve the chat-agent in time? |
|
any timeline on this getting shipped? |
Fixes #13054.
WebSocket upgrade requests for dev-mode worker service bindings currently get routed through
__VITE_MIDDLEWARE__, which only has the Node middleware bridge. That makes proxied worker-to-worker WebSocket upgrades miss the real entry worker and crash in Miniflare's loopback upgrade path.This change routes
Upgrade: websocketrequests in__vite_proxy_worker__straight toENTRY_USER_WORKER.fetch(...)while keeping normal HTTP requests on the existing Vite middleware path. I also added a focused unit test for the proxy dispatch logic and amulti-workerplayground regression coveringWorker A -> Worker BWebSocket proxying in dev mode.Local validation:
node node_modules/vitest/vitest.mjs run src/__tests__/vite-proxy-worker.spec.tsnode node_modules/tsdown/dist/run.mjsnode node_modules/typescript/bin/tsc -b packages/vite-plugin-cloudflare/playground/multi-worker/tsconfig.jsonA picture of a cute animal (not mandatory, but encouraged)