Skip to content

fix(dev): bind Studio, Preview, and demo-site to IPv4 loopback - #100

Merged
7shep merged 2 commits into
mainfrom
fix/vite-loopback-host
Aug 2, 2026
Merged

fix(dev): bind Studio, Preview, and demo-site to IPv4 loopback#100
7shep merged 2 commits into
mainfrom
fix/vite-loopback-host

Conversation

@7shep

@7shep 7shep commented Aug 1, 2026

Copy link
Copy Markdown
Owner

Found while debugging "terminal says the dev server is up, but the browser can't connect to localhost:5173."

Root cause

None of the three dev-server vite.config.ts files set server.host. Without it, Vite bound only IPv6 loopback (::1) on this environment. Meanwhile the trusted local runtime hardcodes 127.0.0.1 for its origin allowlist and bootstrap flow (packages/local-runtime/src/cli.ts:10-11, docs/PHASE3_RUNTIME.md: "binds an ephemeral port on 127.0.0.1 only"). That mismatch causes two separate symptoms:

  1. A browser whose localhost resolution or network path favors IPv4 (VPNs, some proxy setups, certain Windows IPv6 configs) gets connection-refused against a server that genuinely started successfully.
  2. Even once connected via [::1], a real trusted-runtime session would reject Studio's origin, since the runtime only allowlists http://127.0.0.1:5173.

Verification

Directly tested before/after on the affected machine:

http://127.0.0.1:PORT/ http://[::1]:PORT/
Before connection refused 200 OK
After 200 OK

Get-NetTCPConnection confirmed the socket moves from ::1 to 127.0.0.1 listen after the change. pnpm --filter @universal/studio typecheck, @universal/preview typecheck, @universal/demo-site typecheck, and prettier --check on the three files are clean.

Change

Adds host: '127.0.0.1' to server in apps/studio/vite.config.ts, apps/preview/vite.config.ts, and examples/demo-site/vite.config.ts. No behavior change for contributors whose Vite already happened to bind IPv4/dual-stack.

Co-Authored-By: Claude noreply@anthropic.com

Without an explicit `server.host`, Vite defaulted to IPv6-loopback-only
(`::1`) on at least one contributor's Windows setup, while the trusted
local runtime's origin allowlist and bootstrap flow are hardcoded to
`127.0.0.1` (packages/local-runtime/src/cli.ts, docs/PHASE3_RUNTIME.md).
That mismatch produced two symptoms: browsers whose localhost resolution
or network path favored IPv4 couldn't reach a dev server the terminal
reported as running, and a real runtime session would reject Studio's
origin even once connected.

Setting `host: '127.0.0.1'` explicitly on all three dev servers matches
what the runtime already expects and removes the platform-dependent
IPv6-vs-IPv4 guesswork. Verified: before the fix, `http://127.0.0.1:PORT`
was refused while `http://[::1]:PORT` succeeded; after, Vite binds and
serves on 127.0.0.1 directly.

Co-Authored-By: Claude <noreply@anthropic.com>
@vercel

vercel Bot commented Aug 1, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
universal Ready Ready Preview Aug 1, 2026 8:00pm

frontend/vite.config.ts had no server config at all, so it defaulted
to Vite's standard port 5173 -- the same port Studio uses -- and to
IPv6-loopback-only binding. Once frontend joined the workspace dev
fleet, `pnpm dev` started both on port 5173 simultaneously: Studio on
127.0.0.1 (this branch's earlier fix) and frontend on ::1. Since a
browser's default localhost resolution tries IPv6 first, this made
frontend win the race and silently serve at localhost:5173 instead of
Studio, with no error from either side.

Gives frontend an explicit 127.0.0.1:5176 with strictPort, matching
the other three dev servers, so a real collision now fails loudly
instead of one server silently masking another. Updates SETUP.md's
port table and override examples.

Verified: `vite` in frontend/ now reports "Local: http://127.0.0.1:5176/".

Co-Authored-By: Claude <noreply@anthropic.com>
@7shep
7shep merged commit 38fc640 into main Aug 2, 2026
7 checks passed
7shep added a commit that referenced this pull request Aug 3, 2026
Mirrors PR #100 and PR #101 onto this branch for local testing:

- Studio, Preview, and demo-site now bind server.host to 127.0.0.1
  instead of defaulting to IPv6-loopback-only, matching what the
  trusted local runtime's origin allowlist already expects.
- apps/studio/public/dev-runtime.local.js and
  apps/preview/public/dev-runtime.local.js let window.__UNIVERSAL_RUNTIME__
  be set before app code runs, so a real local runtime can be connected
  for manual testing instead of always falling back to the fixture client.

Co-Authored-By: Claude <noreply@anthropic.com>
7shep added a commit that referenced this pull request Aug 3, 2026
frontend/vite.config.ts had no server config, defaulting to port 5173
(colliding with Studio) and IPv6-loopback-only binding. Since a
browser's localhost resolution tries IPv6 first, frontend silently won
that race over Studio's IPv4 binding, serving the marketing site at
localhost:5173 instead of Studio with no error from either side.

Mirrors PR #100's follow-up commit: explicit 127.0.0.1:5176 with
strictPort, and updates SETUP.md's port table and override examples.

Co-Authored-By: Claude <noreply@anthropic.com>
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