Skip to content

fix(microfrontend-template): pass through WebSocket upgrade responses as-is#964

Open
seivad wants to merge 1 commit intocloudflare:mainfrom
seivad:fix/microfrontend-websocket-101-passthrough
Open

fix(microfrontend-template): pass through WebSocket upgrade responses as-is#964
seivad wants to merge 1 commit intocloudflare:mainfrom
seivad:fix/microfrontend-websocket-101-passthrough

Conversation

@seivad
Copy link

@seivad seivad commented Mar 23, 2026

Title:

fix(microfrontend-template): pass through WebSocket upgrade responses as-is

Description

Fixes a bug where WebSocket connections through the microfrontend router would silently fail.

When an upstream service (Durable Objects, Agents SDK, PartyKit, etc.) responds with HTTP 101 (WebSocket upgrade), the response must be returned directly. The existing passthrough path wrapped the response in new Response(upstreamResp.body, ...), which drops the webSocket property that carries the client-side WebSocket object. The connection appears to establish but immediately closes.

The fix adds an early return for status === 101 responses immediately after upstream.fetch(), before any header or body processing.

Checklist

This PR modifies an existing template file only — no new template is being introduced, so the new-template checklist does not apply.

  • Existing template (microfrontend-template) is unaffected for all non-WebSocket traffic
  • Fix is non-breaking: the early return only triggers on HTTP 101 responses

… as-is

When an upstream service responds with HTTP 101 (WebSocket upgrade), the
response must be returned directly without wrapping it in a new Response().
Constructing a new Response() drops the webSocket property that carries the
client-side WebSocket object, causing the connection to silently close
immediately after appearing to establish.

This fix adds an early-return for 101 responses before any header or body
processing, restoring WebSocket support for Durable Objects, Agents SDK,
PartyKit, and any other WebSocket-based upstream service.
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.

1 participant