fix: use location.host for web browsers without breaking Tauri#5967
Closed
majiayu000 wants to merge 1 commit intoanomalyco:devfrom
Closed
fix: use location.host for web browsers without breaking Tauri#5967majiayu000 wants to merge 1 commit intoanomalyco:devfrom
majiayu000 wants to merge 1 commit intoanomalyco:devfrom
Conversation
This fix addresses issue anomalyco#5928 where `opencode --port=8080` fails because the port is hardcoded to 4096. The previous fix (anomalyco#5949) was reverted because it broke the Tauri desktop application. This implementation: - Preserves the priority of `window.__OPENCODE__` check for Tauri apps - Only adds localhost/127.0.0.1 detection as a fallback before "/" - Uses `location.host` to dynamically get the correct port for web browsers - Does not affect Tauri desktop app which has its own port management Fixes anomalyco#5928 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <[email protected]>
Collaborator
|
5928 got fixed so I think we can close this? |
Contributor
Author
|
Thanks for the update. |
|
@rekram1-node re:
#5928 was closed by #5949 which was then reverted in eebbd73 due to #5949 (comment) and this PR was the new attempt. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
opencode --port=8080fails due to hardcoded port 4096location.hostto dynamically get the correct port for web browsersChanges
This implementation carefully preserves the execution order to avoid breaking Tauri:
window.__OPENCODE__check remains in its original positionlocation.hostwhich includes both hostname and portWhy This Works
Three Runtime Environments:
window.__OPENCODE__location.hosttauri://localhosthttp://127.0.0.1:${port}(line 37)localhost:8080http://localhost:8080(line 41-42)opencode.aihttp://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.hostinstead ofwindow.__OPENCODE__.port, breaking desktop functionality.Why This Fix Works:
window.__OPENCODE__, so they skip to localhost checkwindow.__OPENCODE__, so they never reach localhost checkTesting
opencode --port=8080Fixes #5928
🤖 Generated with Claude Code
Co-Authored-By: Claude Sonnet 4.5 [email protected]