[PR #5967] fix: use location.host for web browsers without breaking Tauri #11671

Closed
opened 2026-02-16 18:16:35 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/5967

State: closed
Merged: No


Summary

  • Fixes issue #5928 where opencode --port=8080 fails due to hardcoded port 4096
  • Addresses the revert of PR #5949 which broke Tauri desktop app
  • Adds localhost/127.0.0.1 detection as a fallback before "/"
  • Uses location.host to dynamically get the correct port for web browsers

Changes

This implementation carefully preserves the execution order to avoid breaking Tauri:

  1. Preserved Tauri priority: window.__OPENCODE__ check remains in its original position
  2. Added web browser fallback: New localhost/127.0.0.1 check before the "/" fallback
  3. Dynamic port detection: Uses location.host which includes both hostname and port

Why This Works

Three Runtime Environments:

Environment window.__OPENCODE__ location.host Result
Tauri Desktop Exists tauri://localhost Uses http://127.0.0.1:${port} (line 37)
Web Browser (localhost) Not exists localhost:8080 Uses http://localhost:8080 (line 41-42)
Production (opencode.ai) Not exists opencode.ai Uses http://localhost:4096 (line 36)

Why Previous Fix Failed:

The previous PR #5949 changed the condition order, causing Tauri apps (which run on localhost) to use location.host instead of window.__OPENCODE__.port, breaking desktop functionality.

Why This Fix Works:

  • Tauri check happens before localhost check (line 37 vs line 41)
  • Web browsers don't have window.__OPENCODE__, so they skip to localhost check
  • Tauri apps have window.__OPENCODE__, so they never reach localhost check

Testing

  • Type checking passed
  • Build completed successfully
  • Ready for manual testing with opencode --port=8080

Fixes #5928

🤖 Generated with Claude Code

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

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/5967 **State:** closed **Merged:** No --- ## Summary - Fixes issue #5928 where `opencode --port=8080` fails due to hardcoded port 4096 - Addresses the revert of PR #5949 which broke Tauri desktop app - Adds localhost/127.0.0.1 detection as a fallback before "/" - Uses `location.host` to dynamically get the correct port for web browsers ## Changes This implementation carefully preserves the execution order to avoid breaking Tauri: 1. **Preserved Tauri priority**: `window.__OPENCODE__` check remains in its original position 2. **Added web browser fallback**: New localhost/127.0.0.1 check before the "/" fallback 3. **Dynamic port detection**: Uses `location.host` which includes both hostname and port ## Why This Works ### Three Runtime Environments: | Environment | `window.__OPENCODE__` | `location.host` | Result | |-------------|----------------------|-----------------|--------| | **Tauri Desktop** | ✅ Exists | `tauri://localhost` | Uses `http://127.0.0.1:${port}` (line 37) | | **Web Browser (localhost)** | ❌ Not exists | `localhost:8080` | Uses `http://localhost:8080` (line 41-42) | | **Production (opencode.ai)** | ❌ Not exists | `opencode.ai` | Uses `http://localhost:4096` (line 36) | ### Why Previous Fix Failed: The previous PR #5949 changed the condition order, causing Tauri apps (which run on localhost) to use `location.host` instead of `window.__OPENCODE__.port`, breaking desktop functionality. ### Why This Fix Works: - Tauri check happens **before** localhost check (line 37 vs line 41) - Web browsers don't have `window.__OPENCODE__`, so they skip to localhost check - Tauri apps have `window.__OPENCODE__`, so they never reach localhost check ## Testing - ✅ Type checking passed - ✅ Build completed successfully - Ready for manual testing with `opencode --port=8080` Fixes #5928 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
yindo added the pull-request label 2026-02-16 18:16:35 -05:00
yindo closed this issue 2026-02-16 18:16:35 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11671