Skip to content

Commit ec3e160

Browse files
committed
fix(kit): cast nuxt addVitePlugin calls past duplicate vite peer types
pnpm resolves vite's optional @vitejs/devtools peer independently for each Nuxt-hosted devtools app and for @nuxt/kit's own dependency chain, so addVitePlugin ends up typed against a structurally distinct (but runtime-identical) vite install than the plugin objects we hand it. vue-tsc rejected this as a foreign Plugin instance after the vite 8.3.1 bump exposed the mismatch through the DevEnvironment hotUpdate hook.
1 parent 59260bf commit ec3e160

3 files changed

Lines changed: 36 additions & 8 deletions

File tree

‎packages/oxc/src/modules/rpc.ts‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
import type { PluginWithDevTools } from '@vitejs/devtools-kit'
12
import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
23
import { DevToolsServer } from '../../../core/src/node/plugins/server'
34
import { rpcFunctions } from '../node/rpc'
45

6+
// `@nuxt/kit` types `addVitePlugin` against whatever `vite` install pnpm
7+
// resolves for its own peer chain, which can differ from the one our
8+
// plugins are built against even on the same `vite` version — cast past
9+
// the resulting structural mismatch.
10+
function addDevToolsVitePlugin<T extends { name: string }>(plugin: T): void {
11+
addVitePlugin(plugin as unknown as Parameters<typeof addVitePlugin>[0])
12+
}
13+
514
export default defineNuxtModule({
615
meta: {
716
name: 'devtools-rpc',
817
configKey: 'devtoolsRpc',
918
},
1019
setup() {
11-
addVitePlugin({
20+
const rpcPlugin: PluginWithDevTools = {
1221
name: 'vite:devtools:oxc',
1322
devtools: {
1423
setup(ctx) {
@@ -17,8 +26,9 @@ export default defineNuxtModule({
1726
}
1827
},
1928
},
20-
})
29+
}
30+
addDevToolsVitePlugin(rpcPlugin)
2131

22-
addVitePlugin(DevToolsServer())
32+
addDevToolsVitePlugin(DevToolsServer())
2333
},
2434
})
Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
1+
import type { PluginWithDevTools } from '@vitejs/devtools-kit'
12
import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
23
import { DevToolsServer } from '../../../core/src/node/plugins/server'
34
import { rpcFunctions } from '../node/rpc'
45

6+
// `@nuxt/kit` types `addVitePlugin` against whatever `vite` install pnpm
7+
// resolves for its own peer chain, which can differ from the one our
8+
// plugins are built against even on the same `vite` version — cast past
9+
// the resulting structural mismatch.
10+
function addDevToolsVitePlugin<T extends { name: string }>(plugin: T): void {
11+
addVitePlugin(plugin as unknown as Parameters<typeof addVitePlugin>[0])
12+
}
13+
514
export default defineNuxtModule({
615
meta: {
716
name: 'devtools-rpc',
817
configKey: 'devtoolsRpc',
918
},
1019
setup() {
11-
addVitePlugin({
20+
const rpcPlugin: PluginWithDevTools = {
1221
name: 'vite:devtools:rolldown',
1322
devtools: {
1423
setup(ctx) {
@@ -17,8 +26,9 @@ export default defineNuxtModule({
1726
}
1827
},
1928
},
20-
})
29+
}
30+
addDevToolsVitePlugin(rpcPlugin)
2131

22-
addVitePlugin(DevToolsServer())
32+
addDevToolsVitePlugin(DevToolsServer())
2333
},
2434
})

‎packages/vite/src/modules/rpc.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,21 @@ import { addVitePlugin, defineNuxtModule } from '@nuxt/kit'
22
import { DevToolsServer } from '../../../core/src/node/plugins/server'
33
import { DevToolsViteInspect } from '../node/inspect/plugin'
44

5+
// `@nuxt/kit` types `addVitePlugin` against whatever `vite` install pnpm
6+
// resolves for its own peer chain, which can differ from the one our
7+
// plugins are built against even on the same `vite` version — cast past
8+
// the resulting structural mismatch.
9+
function addDevToolsVitePlugin<T extends { name: string }>(plugin: T): void {
10+
addVitePlugin(plugin as unknown as Parameters<typeof addVitePlugin>[0])
11+
}
12+
513
export default defineNuxtModule({
614
meta: {
715
name: 'devtools-rpc',
816
configKey: 'devtoolsRpc',
917
},
1018
setup() {
11-
addVitePlugin(DevToolsViteInspect())
12-
addVitePlugin(DevToolsServer())
19+
addDevToolsVitePlugin(DevToolsViteInspect())
20+
addDevToolsVitePlugin(DevToolsServer())
1321
},
1422
})

0 commit comments

Comments
 (0)