-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Overriding HMR port with vite.server.hmr.port
no longer working
#3017
Comments
I don't think this is related to #1517 anymore. It's probably more likely to be related to our now using the Vite dev server in SvelteKit dev mode - or else some other unrelated unexpected Vite change. The merged config we're passing to Vite does include the expected |
When I manually edit https://github.com/vitejs/vite/blob/2efc1e571ff6e80a16104c4cb0f888a38c0b30c9/packages/vite/src/node/server/ws.ts#L33 to include |
It seems like we don't want |
The following worked for me. Use clientPort, not port.
|
Thanks, I was able to make that work, although it was in conjunction with Docker and binding to the port that Vite was by default listening on. This appears to be a good enough workaround for me for now. I'm tempted to leave this issue open though (rather than closing it in favor of the Vite issue I opened) because this isn't going to be an option for people who aren't using Docker or some other proxy/mechanism for mapping between ports. I'll leave the decision of whether to close this to the other maintainers. |
Middleware mode means you bring your own Connect/Express/Polka server and run Vite as a middleware in that server. We did that at one point (which is probably when this worked as you expected), but now let Vite manage running its own Connect server. I see that an issue was also opened in the Vite tracker and that this is reproducible without SvelteKit involved: vitejs/vite#6068 |
This has been fixed in Vite 2.9: vitejs/vite#7282 |
@benmccann I have a |
I've also commented on vitejs/vite#6068 and that has been re-opened. |
Sent a new fix, so I expect it to be addressed in 2.9. I'll close this one and use the Vite issue to track it |
@benmccann Also running into this after upgrading to the latest released SvelteKit today. It was a pretty big jump from I see you pushed Upgrade to Vite 2.9 just a few hours ago that might fix this, and once SvelteKit My setup is a little different than @Conduitry as I have my dotnet backend (running on https://localhost:5443) proxying all calls to the SvelteKit/Vite server (http://localhost:3000) to not have to deal with CORS, handles HTTPS, etc.
I currently use this setup in vite: {
server: {
hmr: {
protocol: 'wss',
port: 5443,
},
} |
SvelteKit and the Vite plugin depend on |
@Conduitry @benmccann Looks like I'm already on I also looked in so looks like Vite 2.9 didn't fix the issue. Not sure if it's the |
I think I found the right combination to use this time (for Vite 2.9)... vite: {
server: {
hmr: {
protocol: 'ws',
clientPort: 3000,
},
} for Vite 2.7 (what I had before), this worked... vite: {
server: {
hmr: {
protocol: 'wss',
port: 5443,
},
} and prior to that I used: vite: {
server: {
hmr: {
protocol: 'ws',
port: 3001,
},
} Can't say I know what I'm doing each time I upgrade Vite a minor release or two and it breaks HMR, but at least it works again :). Sorry for the noise but maybe this will help someone else in the future (I recall a few other SvelteKit issue threads with a lot of sharing configs / trial and error. |
This comment was marked as duplicate.
This comment was marked as duplicate.
Letting you know that I spent like 3 hours this morning doing trial and error to make this work only to find through your comment (and gleaning from a couple others) that SvelteKit apparently forces Vite to try and establish a websocket connection to To expand on your fix, I had to change the port in the docker configurations for my app to Thanks again, I was going crazy. |
Describe the bug
If you specify the Vite config
server.hmr.port
to override the port that the websocket connection for HMR uses, Vite dev runtime code in the browser attempts to connect to this port but the connection fails, triggering repeated refreshes of the page.Reproduction
From the starter template, add
to your
svelte.config.js
to set the https://vitejs.dev/config/#server-hmr setting.Open the browser and look at the console and network tab.
Logs
System Info
Severity
blocking an upgrade
Additional Information
This used to work, although I haven't chased down which version this broke in. (This would be inconvenient to do, because of all the other intended breaking changes that Kit has had in the past months.) The first place I'm going to look is the #1517 stuff though.
The text was updated successfully, but these errors were encountered: