Skip to content

Commit b5f9f8a

Browse files
authored
fix(devtools): run defineViteDevToolsPlugin only for client vite (#977)
1 parent 4853d04 commit b5f9f8a

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

packages/devtools/src/module-main.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export async function enableModule(options: ModuleOptions, nuxt: Nuxt) {
9090
connectDevToolsKit?.(ctx)
9191
},
9292
},
93-
}))
93+
}), { server: false })
9494
addPlugin({
9595
src: join(runtimeDir, 'plugins/vite-devtools.client'),
9696
mode: 'client',

packages/devtools/src/server-rpc/index.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,13 @@ export function setupRPC(nuxt: Nuxt, options: ModuleOptions) {
136136
* Called from the Vite DevTools plugin setup callback.
137137
*/
138138
function connectDevToolsKit(ctx: DevToolsNodeContext) {
139+
/**
140+
* guarded to keep the first connection (client Vite), since Nuxt creates
141+
* two Vite instances and the second (server) one has 0 WebSocket clients.
142+
* If we don't guard this, the server connection will overwrite the client connection and break all RPC calls from server to client.
143+
*/
144+
if (devtoolsKitCtx)
145+
return
139146
devtoolsKitCtx = ctx
140147
const host = ctx.rpc
141148

0 commit comments

Comments
 (0)