fix: infer client port from page location#7463
Conversation
| const socketHost = `${__HMR_HOSTNAME__ || location.hostname}:${ | ||
| __HMR_PORT__ || location.port | ||
| }${__HMR_BASE__}` |
There was a problem hiding this comment.
I think we should still support hmr.port: false, let's keep it to merge this PR and we can discuss for 3.0 if we want to deprecate the option. I don't see much harm in keeping it now that we already have it. @jeoy, I'm interested to hear your opinion, and feedback in case you could test this PR for your use case.
There was a problem hiding this comment.
@patak-dev Sure I will try to keep it.
I have to admit I don't fully get the use-case of #6624, but I thought if it is really not needed it might be good to remove now, since it was only released in beta versions 🤔 .
And I agree with #6624 (comment) that the port type number | false is a bit weird.
There was a problem hiding this comment.
Oh, you are right. I didn't consider that this option was not still released in a stable version. Good point. @jeoy if this PR covers your use case, I agree with @lukashass here that we should revert #6624 until we find a valid use case for it.
There was a problem hiding this comment.
Furthermore I just discovered that setting hmr.port: false currently doesn't have the desired effect, since port will default to config.server.port in this line:
|
This looks good to me @lukashass, thanks for working on the PR. @mehulmpt, @edorgeville maybe you could also check this PR is working for you? |
|
@patak-dev Can you rerun the CI? |
|
See comment #7463 (comment), @jeoy let's merge this one to avoid introducing a new option if it isn't needed. Please create a new PR if we're missing something here to add the option back and let's re-discuss it. Thanks! @lukashass thanks again for digging into this ❤️ |
|
So does this make it impossible for our setup to work when we have a Java server running on port 8080 and a Vite server running on a random port and want the browser to make the websocket connection directly to the Vite server? |
|
@Artur- thanks for testing, let's revert this PR so we can release 2.9 today. @lukashass we can try this fix again taking into account @Artur- case later. |
|
@Artur- Are you integrating the vite page in an iframe? Edit: I just found out that vite works just fine in an iframe, since |
|
No iframe. We are proxying the Vite requests through a |
|
I'm in the same situation as @Artur-. I often embed my live apps in subdirectories (or even within larger pages) of my server-side applications. The live apps will therefore load on It's easy to fix this by setting I have two ideas on how to proceed:
|
|
To @baileyherbert 's points, fixing this with an opt-in configuration doesn't really make sense, as we can already do that by using I work at CodeSandbox, and our use-case is that we reverse-proxy from an URL like A better inference, that combines both this and #6624, and might coincidentally fix @Artur- and @baileyherbert 's use-cases, is simply: if So if This would also work for our use-case - the websocket URL for |
|
Nice idea!! That would work perfectly for me. 👍 Yesterday, I tried tunneling vite through Cloudflare Argo to quickly share a project with a colleague. I couldn't get it to connect with the vite backend on both the tunnel Yet, say you're running a large project on |
|
I think we could make it work if we expose to the client the fact that |
|
Considering the use-cases of @Artur- and @baileyherbert, this really is about finding a better default rather than just fixing the existing behaviour 🤯 After reading your ideas I came to the following possible values for
|
Description
Closes #3093 and closes #5153.
By inferring the HMR client port from the current page location, vite can be run behind reverse proxies without extra configuration.
Partly reverts #6624.
Additional context
TODO
path.posix.normalizereally did not have any meaningful effectBuilds partly on #4168
Possible follow-up: infer defaults from
document.currentScriptand/orimport.meta.urlWhat is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123).