Skip to content

fix: support mobile access when dev server binds to 0.0.0.0#1680

Open
42tg wants to merge 2 commits intopingdotgg:mainfrom
42tg:fix/mobile-access-binding
Open

fix: support mobile access when dev server binds to 0.0.0.0#1680
42tg wants to merge 2 commits intopingdotgg:mainfrom
42tg:fix/mobile-access-binding

Conversation

@42tg
Copy link
Copy Markdown

@42tg 42tg commented Apr 2, 2026

Summary

  • Vite dev server respects T3CODE_HOST env var for network binding (e.g. T3CODE_HOST=0.0.0.0)
  • HMR auto-detects host when binding to 0.0.0.0 instead of hardcoding localhost
  • Add T3CODE_HOST to turbo.json global env passthrough

Test plan

  • Run with T3CODE_HOST=0.0.0.0 bun dev and access from another device on the same network
  • Verify HMR still works when accessing from a remote host
  • Verify default localhost behavior is unchanged when T3CODE_HOST is not set

Note

Low Risk
Low risk dev-only configuration and URL resolution changes; main risk is misrouting HMR/WebSocket connections when running with custom hosts.

Overview
Improves remote-device access to the dev server by making Vite bind to a configurable host via T3CODE_HOST (defaulting to localhost) and adjusting HMR config to avoid hardcoding localhost when not running locally.

Updates resolveServerUrl to rewrite localhost to the current window.location.hostname when the app is accessed from a non-localhost host, ensuring WebSocket connections reach the correct machine. Exposes T3CODE_HOST through Turborepo globalEnv so the setting propagates in tasks.

Written by Cursor Bugbot for commit a2a9afe. This will update automatically on new commits. Configure here.

Note

Fix mobile access when dev server binds to 0.0.0.0

  • Adds T3CODE_HOST env var support to vite.config.ts so the dev server binds to a configurable host (default localhost). HMR omits an explicit host when not on localhost to allow correct host resolution.
  • Updates resolveServerUrl in utils.ts to replace localhost in resolved URLs with window.location.hostname when the page is accessed from a non-localhost host.
  • Exposes T3CODE_HOST as a global env var in turbo.json.

Macroscope summarized a2a9afe.

@github-actions github-actions bot added size:S 10-29 changed lines (additions + deletions). vouch:unvouched PR author is not yet trusted in the VOUCHED list. labels Apr 2, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

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: b19d87fa-e6cf-4e13-a090-e23d9cca75b6

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.

@42tg 42tg force-pushed the fix/mobile-access-binding branch from c7a2337 to b41dfb7 Compare April 2, 2026 10:31
@42tg 42tg force-pushed the fix/mobile-access-binding branch from b41dfb7 to 38fd662 Compare April 2, 2026 10:40
@macroscopeapp
Copy link
Copy Markdown
Contributor

macroscopeapp bot commented Apr 2, 2026

Approvability

Verdict: Approved

Development tooling change to support mobile device testing when the dev server binds to 0.0.0.0. The changes are limited to Vite config and a simple URL replacement for non-localhost access - no production behavior is affected.

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

- Vite server respects T3CODE_HOST for network binding
- Skip hardcoded VITE_WS_URL when host is not localhost, letting the
  client derive WS URL from window.location
- HMR auto-detects host when binding to 0.0.0.0
@42tg 42tg force-pushed the fix/mobile-access-binding branch from 38fd662 to 913863c Compare April 2, 2026 11:35
Copy link
Copy Markdown
Contributor

@cursor cursor bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

// resolved URL with the actual page hostname so the connection reaches the server.
if (rawUrl.includes("localhost") && window.location.hostname !== "localhost") {
rawUrl = rawUrl.replace("localhost", window.location.hostname);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Naive string replace risks matching localhost in non-hostname positions

Low Severity

rawUrl.includes("localhost") and rawUrl.replace("localhost", ...) perform raw string matching rather than targeting the URL's hostname specifically. Since new URL(rawUrl) is constructed on the very next line, the hostname check and replacement could be done on the parsed URL object (e.g., parsedUrl.hostname === "localhost" and parsedUrl.hostname = window.location.hostname), avoiding any risk of matching "localhost" as a substring in paths, query params, or other hostname parts like notlocalhost.example.com.

Fix in Cursor Fix in Web

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.

2 participants