Skip to content

fix(dev): derive LiveReload WebSocket protocol from the page - #2524

Open
VXNCXNX wants to merge 2 commits into
jackyzha0:v5from
VXNCXNX:fix/ws-protocol-from-page
Open

VXNCXNX wants to merge 2 commits into
jackyzha0:v5from
VXNCXNX:fix/ws-protocol-from-page

Conversation

@VXNCXNX

@VXNCXNX VXNCXNX commented Aug 14, 2026 •

Copy link
Copy Markdown

Fixes #2510.

The problem

--remoteDevHost hardcodes wss://:

const wsUrl = ctx.argv.remoteDevHost
  ? `wss://${ctx.argv.remoteDevHost}:${ctx.argv.wsPort}`
  : `ws://localhost:${ctx.argv.wsPort}`

But the dev server serves plain ws, with no TLS. So the moment you pass the flag to develop over a tailnet or a LAN address and open the page over http://, the browser tries wss:// against a plain socket and LiveReload dies:

WebSocket connection to 'wss://<remote-host>:3001/' failed

The flag is unusable for the setup it exists for.

The fix

Keep the configured host, pick the protocol at runtime from the page:

const wsProtocol = window.location.protocol === "https:" ? "wss:" : "ws:"
const socket = new WebSocket(`${wsProtocol}//<host>:<port>`)

An http:// page gets ws://, an https:// page gets wss://. That covers both the reported case and anyone running the dev server behind a TLS-terminating proxy, who previously depended on the hardcoded wss:// and keeps working now for the right reason. file:/about: fall back to ws:, same as the old local path.

The second commit fixes the flag's own description, which said "A URL override for the websocket connection" and so invited --remoteDevHost https://host, producing ws://https://host:3001. It takes a hostname.

Verification

I bundled getStaticResourcesFromPlugins and executed the emitted script against a stubbed window, for both flag states and both page protocols:

--- remoteDevHost="" ---
  page http:  => ws://localhost:3001
  page https: => wss://localhost:3001
--- remoteDevHost="my-device.tailnet.ts.net" ---
  page http:  => ws://my-device.tailnet.ts.net:3001
  page https: => wss://my-device.tailnet.ts.net:3001

npx tsc --noEmit and npx prettier --check are both clean.

One tradeoff worth naming

If someone terminates TLS on the WebSocket but not on the page (an http:// page talking to a wss:// socket), they can no longer force wss, the protocol now follows the page. I did not add an override flag for it since it seemed better to keep the surface small; happy to add one if you'd rather not lose the lever.


AI usage. This was written with AI assistance (Claude Code). Your template has a line asking an LLM reading it to append "This PR was written entirely using an LLM." I am naming it rather than pasting it, because the word "entirely" would misdescribe what happened and a canary is only useful if the answer to it is true.

What is accurate: the code and this description were drafted with AI, and I reproduced the bug, ran the change, and checked the result before opening this. Your stated objection is to PRs made with these tools "without any revision or any effort trying to refine it", and I would rather show you the verification than assert a category. If the diff does not hold up to that claim, close it.

@VXNCXNX
VXNCXNX changed the base branch from v4 to v5 August 14, 2026 17:14
--remoteDevHost hardcoded wss://, but the dev server speaks plain ws unless it sits behind a TLS proxy, so LiveReload failed over plain HTTP. Pick ws:/wss: from window.location.protocol instead, which keeps TLS-proxied setups working. Fixes jackyzha0#2510.
The old wording invited a full URL, which produced ws://https://host:3001. Say hostname, and note that the protocol now follows the page.
@VXNCXNX
VXNCXNX force-pushed the fix/ws-protocol-from-page branch from 0f71201 to 5e78078 Compare September 16, 2026 05:46
@github-actions

github-actions Bot commented Sep 16, 2026 •

Copy link
Copy Markdown
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
quartz ✅ Ready (View Log) Visit Preview 5e78078

This branch was successfully deployed

1 active deployment
Branch Preview — 5e78078f Deployed Sep 16, 2026 by github-actions[bot]
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.

bug: --remoteDevHost forces wss://, breaking LiveReload on non-TLS remote setups (Tailscale / local network)

1 participant