@devries-cameron20 / t3code-1 / commits / a87f691bd4
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(preview): open local environment ports on localhost (#7300)

Guilherme Barros committed Aug 18, 2026 at 19:39 UTC a87f691bd40c9e3c87715e3ce99ab39a584bdd1e
2 files changed +20 -4
apps/web/src/browser/browserTargetResolver.test.ts
+13 -1
@@ -173,7 +173,19 @@ describe("browser target resolver", () => {
173 kind: "environment-port",
174 port: 5173,
175 }).resolvedUrl,
176 - ).toBe("http://[::1]:5173/");
176 + ).toBe("http://localhost:5173/");
177 + });
178 +
179 + it("maps local IPv4 environment ports onto localhost for dual-stack guests", async () => {
180 + readPreparedConnection.mockReturnValue({ httpBaseUrl: "http://127.0.0.1:3773" });
181 + const { resolveBrowserNavigationTarget } = await import("./browserTargetResolver");
182 + expect(
183 + resolveBrowserNavigationTarget(EnvironmentId.make("environment-1"), {
184 + kind: "environment-port",
185 + port: 5173,
186 + path: "/app",
187 + }).resolvedUrl,
188 + ).toBe("http://localhost:5173/app");
189 });
190
191 it("leaves malformed input for the normal navigation error path", async () => {
apps/web/src/browser/browserTargetResolver.ts
+7 -3
@@ -178,9 +178,13 @@ const resolveEnvironmentPortTarget = (
178 const protocol = target.protocol ?? "http";
179 const path = target.path?.startsWith("/") ? target.path : `/${target.path ?? ""}`;
180 const normalizedEnvironmentHost = environmentUrl.hostname.replace(/^\[|\]$/g, "");
181 - const resolvedHost = normalizedEnvironmentHost.includes(":")
182 - ? `[${normalizedEnvironmentHost}]`
183 - : normalizedEnvironmentHost;
181 + // Local loopback environments should advertise `localhost` so Chromium
182 + // dual-stack lookup can reach a Vite server bound only to ::1 or 127.0.0.1.
183 + const resolvedHost = isLocalLoopbackHost(normalizedEnvironmentHost)
184 + ? "localhost"
185 + : normalizedEnvironmentHost.includes(":")
186 + ? `[${normalizedEnvironmentHost}]`
187 + : normalizedEnvironmentHost;
188 const resolved = sourceUrl
189 ? new URL(sourceUrl)
190 : new URL(path, `${protocol}://${resolvedHost}:${target.port}`);