-
Notifications
You must be signed in to change notification settings - Fork 40
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
HMR doesn't work when changed in config #122
Comments
I was going through the source code trying to debug the issue, looks like the value from Can you tell me what is the use of the variable const config = await getViteConfig();
const isUsingViteResolvedConfig = Object.entries(config).length > 3;
const vite = await createServer(
mergeConfig(isUsingViteResolvedConfig ? {} : config, {
configFile: Config.viteConfigFile,
clearScreen: false,
appType: "custom",
server: {
middlewareMode: true,
hmr: { server },
},
}),
); |
Hi @anurag-roy, I stumbled on the same problem when I wanted to use WebSocket server myself. What I did was a quick dirty hack to comment out When it comes to answering your question, it is because how |
@szymmis Can confirm, the patch you suggested does work, many thanks! Also thanks for answering my question, makes sense now. I'll take a look at the full code to understand how it runs! |
The biggest problem with this code is that it lacks comments out of my laziness, and in that kind of library code there are a lot of "weird" things going on. If you have any questions about the internals feel free to ask, I'll try to answer it the best I can but even I don't remember everything about why is something written the way it is. For the most part if it's written in a weird way, it had to be written in that way 😅 I think when it comes to resolving this problem, I'll try to detect if there is a You can also try to fiddle with it if you want, any help is greatly appreciated! |
hey, I have say "blame on me" for that issue :( I wrote this code to use the given express server as the HMR server for vite. Otherwise, when using https, hmr would not work at all (#100). I did not realise that one could use the given server for some web socket usage and ask vite to use another port for its hmr. Checking the the implementation of |
Hi @anurag-roy. It's been a long time, but I've finally managed to find some time and tackle this issue. This fix was embarrassingly easy to implement 😅. I hope I didn't broke anything but it seems like it works. I don't know if you are still interested in this change, but I hope you or anybody else in the future will find this useful. @elturpin it is normal to oversee things like that. I also haven't noticed any issues before so no blame on you at all! You did a great job with contributing that change from #100. You can check out the PR #135 if you want. I plan to release it soon in the next 0.17.0 version. |
Hey @szymmis, just tested it out and works perfectly! Thanks a ton! |
How to reproduce
Update the value for
server.hmr.port
in yourvite.config.ts
Expectation
HMR should work via the new port
Actual
HMR does not work, socket connection fails
Context
Just to provide some more context. I am trying to set up my own WebSocket server on the default port, like this
So, I think this is blocking the Vite's HMR websocket server and I want to ask Vite to use another port for that. Is there any other workaround for this?
The text was updated successfully, but these errors were encountered: