Repository navigation
fix: serve the Vite DevTools WebSocket on Nuxt's HTTPS listener - #1156
Conversation
Closes #1152 Co-Authored-By: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
Closes #1152 Co-Authored-By: Claude <noreply@anthropic.com>
|
No actionable comments were generated in the recent review.
|
Summary
With
devServer.httpson Nuxt 4, DevTools never connects (#1152). Nuxt runs Vite in middleware mode, soviteServer.httpServerisnull. Vite DevTools then opens its RPC WebSocket on a plain-HTTP side-car port (9777/9778). The HTTPS page connects withwss://localhost:9778/__ws, and the TLS handshake fails. The client never reaches the authorization step, so no code is printed.Nuxt 5's vite-builder already sets
httpServerto Nuxt's listener (nuxt:dev-listener). This PR adds the same step for Nuxt 4, in a newnuxt:devtools:dev-listenerVite plugin (packages/devtools/src/utils/dev-listener.ts):httpServeris unset andnuxt._devServerListeneris a TLS server, it hands the listener over. Vite DevTools then attaches its socket to the page's own origin and TLS, and advertises{ "path": "/__devtools/__ws" }instead of a port.buildAssetsDirtonuxt.server.upgrade. On Nitro 2, that proxies the socket to the Nitro worker, which ends it under crossws. The result isERR_STREAM_WRITE_AFTER_ENDand a Nuxt restart loop. I hit this while testing a version without the guard. The plugin wrapsnuxt.server.upgradeonce so it skips/__devtools/paths.Plain-HTTP listeners are not changed and keep the side-car, which works for them today. On Nuxt 5 the plugin does nothing, because
httpServeris already set.fixes #1152
Verification
pnpm lint: passes.pnpm typecheck: passes.pnpm test:unit: 21 files, 129 tests pass. This includes the newpackages/devtools/test/dev-listener.test.ts, which covers: the HTTPS handover, Nitro skipping only DevTools upgrades, wrapping once across Vite restarts, plain HTTP left on the side-car, and the SSR server / existinghttpServer/ no listener left alone.nuxt@4.6.3,@nuxt/devtools@4.0.0anddevServer: { https: true }:/__devtools/__connection.jsonadvertised{"port":9777,"path":"__ws"}.{"path":"/__devtools/__ws"}.wss://localhost:3443/__devtools/__wsupgrade returned101, and Vite HMR still upgraded on/_nuxt/.nuxt.serverstill hasupgrade, but this plugin does nothing there because Nuxt 5 setshttpServeritself.Written with the help of Claude Code.