-
Notifications
You must be signed in to change notification settings - Fork 29.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: handle localhost and port in asWebviewUri #130148
Conversation
Not sure how to fix these 😅
|
@@ -55,9 +55,15 @@ export function asWebviewUri( | |||
}); | |||
} | |||
|
|||
let authority = `${resource.scheme}+${resource.authority}.${webviewRootResourceAuthority}`; | |||
if (resource.authority.includes('localhost')) { | |||
const authorityUrl = new URL(`http://${resource.authority}`); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To fix the layer errors, try using our URI
class instead of the built-in URL
class
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I tried that before but the URI
class doesn't have a port (though it does have it in the authority
but then I'd have to split it on the :
, right?) Unless I leave the port out entirely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mjbvz The URI puts the authority
section before the vscode-resource.vscode-webview.net
. So the url becomes localhost:8080.vscode-resource.vscode-webview.net
which is an invalid port.
Ideally, the URI
package could parse the port like URL
.
Possibly? Although I didn't test ports specifically with that fix Did you have a chance to test the issue from #130151? |
I spoke to @code-asher who tested it and I believe it could fix it:
I will have to double-check and follow-up. If it does, I could instead add new tests for URLs with ports |
Closing in favor of #131447 |
This PR fixes #130151
We encountered this error in code-server (fix here: coder/code-server#3895) and noticed that resources weren't loading in webviews due to the wrong URI being returned from
asWebviewUri
.I don't think Codespaces has the issue because it's always running on a standard port and so it won't have a port in the url.
Additional Context
We noticed this happening with a custom VS Code extension having issues loading resources (CSS & JS) in webviews.
I was going to try and reproduce with
vscode
by runningyarn web
but I'm not seeing the option to manually install VSIX files 🤔