fix(core): close ws transport on vite server shutdown - #519
Open
webfansplz wants to merge 1 commit into
Open
Conversation
@vitejs/devtools
@vitejs/devtools-kit
@vitejs/devtools-oxc
@vitejs/devtools-rolldown
@vitejs/devtools-vite
@vitejs/devtools-vitest
commit: |
Contributor
There was a problem hiding this comment.
Pull request overview
Fixes the Vitest shutdown hang (Issue #516) by ensuring the DevTools WebSocket transport is properly closed when the Vite dev server shuts down, including the middleware-mode case where DevTools spins up a standalone WS server.
Changes:
- Expose an idempotent
close()on the WS transport returned bycreateWsServer(). - Thread that
close()throughcreateDevToolsMiddleware()and invoke it from theDevToolsServerplugin’s shutdown hook. - Add focused tests for idempotent cleanup and plugin lifecycle closure; update the public type snapshot accordingly.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| test/snapshots/tsnapi/@vitejs/devtools/index.snapshot.d.ts | Updates the public DevToolsMiddleware type snapshot to include the new close method. |
| packages/core/src/node/ws.ts | Captures the WS transport and exports an idempotent close() wrapper for cleanup. |
| packages/core/src/node/server.ts | Forwards the WS server close() through createDevToolsMiddleware() to consumers. |
| packages/core/src/node/plugins/server.ts | Stores the middleware close() and invokes it in closeBundle() to clean up on Vite shutdown. |
| packages/core/src/node/tests/ws.test.ts | Adds a unit test ensuring repeated close() calls only close the underlying transport once. |
| packages/core/src/node/tests/plugins-server-lifecycle.test.ts | Adds a lifecycle test asserting the plugin triggers middleware cleanup on shutdown. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes #516 by closing the DevTools WebSocket transport during Vite server shutdown.
Vitest runs Vite in middleware mode without an HTTP server, so DevTools creates a standalone WebSocket server. The transport was previously left open after the tests completed, causing Vitest to wait for 10 seconds before reporting a shutdown timeout.
Changes: