Skip to content

fix(core): close ws transport on vite server shutdown - #519

Open
webfansplz wants to merge 1 commit into
mainfrom
fix/vitest-server-close
Open

fix(core): close ws transport on vite server shutdown#519
webfansplz wants to merge 1 commit into
mainfrom
fix/vitest-server-close

Conversation

@webfansplz

Copy link
Copy Markdown
Member

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:

  • exposes an idempotent transport cleanup function
  • forwards cleanup through the DevTools middleware
  • closes the transport in Vite’s closeBundle hook
  • adds lifecycle and repeated-cleanup tests

Copilot AI lite review requested due to automatic review settings August 6, 2026 02:19
@pkg-pr-new

pkg-pr-new Bot commented Aug 6, 2026

Copy link
Copy Markdown

Open in StackBlitz

@vitejs/devtools

npm i https://pkg.pr.new/@vitejs/devtools@519

@vitejs/devtools-kit

npm i https://pkg.pr.new/@vitejs/devtools-kit@519

@vitejs/devtools-oxc

npm i https://pkg.pr.new/@vitejs/devtools-oxc@519

@vitejs/devtools-rolldown

npm i https://pkg.pr.new/@vitejs/devtools-rolldown@519

@vitejs/devtools-vite

npm i https://pkg.pr.new/@vitejs/devtools-vite@519

@vitejs/devtools-vitest

npm i https://pkg.pr.new/@vitejs/devtools-vitest@519

commit: 5bf7450

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 by createWsServer().
  • Thread that close() through createDevToolsMiddleware() and invoke it from the DevToolsServer plugin’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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

devtools makes vitest hang

2 participants