Skip to content

[codex] fix: preserve localhost preview hosts#3499

Merged
juliusmarminge merged 2 commits into
pingdotgg:mainfrom
StiensWout:staging/fix-localhost-preview-host-preservation
Jun 22, 2026
Merged

[codex] fix: preserve localhost preview hosts#3499
juliusmarminge merged 2 commits into
pingdotgg:mainfrom
StiensWout:staging/fix-localhost-preview-host-preservation

Conversation

@StiensWout

@StiensWout StiensWout commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Preserve normalized localhost discovered preview URLs when the prepared connection itself is local loopback.
  • Keep 0.0.0.0 flowing through the existing environment-port normalization path.
  • Keep private remote host remapping for discovered loopback ports.

Root cause

resolveDiscoveredServerUrl(...) treated every loopback discovered URL as an environment-port target. When the prepared connection base was http://127.0.0.1:<port>, that remapped localhost:<port> onto 127.0.0.1:<port>, even though the normalized user-visible URL should stay on localhost.

Impact

Users opening a discovered localhost dev server from a local prepared environment keep the localhost host, which preserves host-specific API allowlists. Wildcard local hosts such as 0.0.0.0 still normalize to a concrete reachable host, and private remote environments still remap discovered loopback ports onto the private environment host.

Validation

  • PATH="$HOME/.vite-plus/bin:$PATH" vp test apps/web/src/browser/browserTargetResolver.test.ts passed: 1 file passed, 7 tests passed.
  • PATH="$HOME/.vite-plus/bin:$PATH" vp check passed: 0 errors; 20 existing unrelated warnings.
  • PATH="$HOME/.vite-plus/bin:$PATH" vp run typecheck passed: completed successfully.

Closes #3124


Note

Low Risk
Small, targeted change to preview URL resolution in the web app with clear tests and no auth or data-path impact.

Overview
resolveDiscoveredServerUrl no longer remaps discovered localhost URLs onto 127.0.0.1 when the prepared environment connection is itself a local loopback host (localhost, 127.0.0.1, or ::1). In that case it returns the normalized URL unchanged so host-specific API allowlists stay on localhost.

Discovered 0.0.0.0 URLs still go through environment-port normalization, and loopback discoveries against private remote prepared bases still remap ports onto the environment host as before. A new isLocalLoopbackHost helper drives the early-return branch, with a unit test covering 127.0.0.1 prepared base + localhost picker input including path, query, and hash.

Reviewed by Cursor Bugbot for commit e581f07. Bugbot is set up for automated code reviews on this repo. Configure here.

Note

Preserve localhost preview hosts in resolveDiscoveredServerUrl

Previously, resolveDiscoveredServerUrl would rewrite loopback URLs through environment-port resolution even when both the discovered host and the prepared connection base host were local loopbacks. This adds a new isLocalLoopbackHost helper and an early-return path in resolveDiscoveredServerUrl that returns the normalized URL unchanged when both sides are loopback (localhost/127.0.0.1/::1) and the discovered host is not 0.0.0.0. If no prepared connection exists, the function now returns the raw input instead of attempting port mapping.

Macroscope summarized e581f07.

StiensWout and others added 2 commits June 22, 2026 09:09
Co-authored-by: Codex <codex@openai.com>
…-host-preservation

[codex] fix: preserve localhost preview hosts
@coderabbitai

coderabbitai Bot commented Jun 22, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 4c38dece-ff70-41d2-904a-09a3b86a687d

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added vouch:unvouched PR author is not yet trusted in the VOUCHED list. size:S 10-29 changed lines (additions + deletions). labels Jun 22, 2026
@macroscopeapp

macroscopeapp Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Approved

Straightforward bug fix that preserves localhost preview URLs when the environment is also running on localhost. The change is small, self-contained, includes a test, and has clear intent with limited scope.

You can customize Macroscope's approvability policy. Learn more.

@juliusmarminge juliusmarminge merged commit c1e2408 into pingdotgg:main Jun 22, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Browser tab localhost getting redirected into 127.0.0.1

2 participants