fix(dev): avoid localhost dual-stack collisions

This commit is contained in:
Shantur Rathore
2026-02-08 20:44:43 +00:00
parent ded31078d4
commit 322a880a02
2 changed files with 8 additions and 1 deletions

View File

@@ -381,6 +381,9 @@ export class CliProcessManager extends EventEmitter {
if (options.dev) {
// Dev: run plain HTTP + Vite dev server proxy.
args.push("--https", "false", "--http", "true")
// Avoid collisions with an already-running server (and dual-stack ::/0.0.0.0 quirks)
// by forcing an ephemeral port in dev.
args.push("--http-port", "0")
} else {
// Prod desktop: always keep loopback HTTP enabled.
args.push("--https", "true", "--http", "true")

View File

@@ -423,7 +423,11 @@ async function main() {
const localProtocol: "http" | "https" = httpStart ? "http" : "https"
const remoteProtocol: "http" | "https" = httpsStart ? "https" : "http"
const localUrl = `${localProtocol}://localhost:${localStart.port}`
// Use an explicit IPv4 loopback address for the "local" URL.
// On macOS, `localhost` often resolves to ::1 first, and it is possible to have
// another instance bound on IPv6 while this instance binds IPv4 (or vice versa),
// which can lead clients to talk to the wrong process.
const localUrl = `${localProtocol}://127.0.0.1:${localStart.port}`
let remoteUrl: string | undefined
if (remoteStart) {
const wantsAll = options.host === "0.0.0.0" || !isLoopbackHost(options.host)