fix: ws never connects after restarting server if server.hmr.server is set #14127
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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
).