-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
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: ws never connects after restarting server if server.hmr.server is set #14127
fix: ws never connects after restarting server if server.hmr.server is set #14127
Conversation
Run & review this pull request in StackBlitz Codeflow. |
I don't know why #14126 happens. It didn't happen on my machine (#14043 (comment)). I was trying to reproduce the same situation by running a script that changes the |
I find that it's pretty intermittent. I tend to notice it happening more when changing branches, or installing/removing dependencies. I would have opened an issue a long time ago if I could create a reproduction, but so far haven't been able to. :( |
It feels good (sorry for you guys) that I'm not the only one and not crazy 😆. That said, it even happened to me once on a completely new project, and after restarting the server it went away. For my local machine with my main project, I can't even start the server anymore without ignoring all the file that trigger a restart. |
This seems to be caused by a problem in |
Description
ws never connected after restarting the server if
server.hmr.server
is set (e.g. Storybook)./cc @IanVS
Reproduction
.env
file in the project root directoryHow it happens
If
server.hmr.server
is not set, when the Vite server restarts, thiswsServer
becomes a different instance.vite/packages/vite/src/node/server/ws.ts
Line 107 in 2d8c841
But since Storybook passes their server to
server.hmr.server
, even if Vite's server restarted,wsServer
is a same instance. Then, the old listener swallows all WebSocket connections and the new listener (started listening after the server restarted) can't handle any requests.Additional context
Found this bug while looking around storybookjs/storybook#22253.
What is the purpose of this pull request?
Before submitting the PR, please make sure you do the following
fixes #123
).