Skip to content

Commit

Permalink
fix: rpc serialization error with Vite configs
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 4, 2025
1 parent 422c8d8 commit 9033ce2
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 13 deletions.
11 changes: 9 additions & 2 deletions packages/devtools/client/composables/rpc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,15 @@ export const rpc = createBirpc<ServerFunctions, ClientFunctions>(clientFunctions
const [namespace, fnName] = name.split(':') as [string, string]
return extendedRpcMap.get(namespace)?.[fnName]
},
onError(error, name) {
console.error(`[nuxt-devtools] RPC error on executing "${name}":`, error)
onFunctionError(error, name) {
console.error(`[nuxt-devtools] RPC error on executing "${name}":`)
console.error(error)
return true
},
onGeneralError(error) {
console.error(`[nuxt-devtools] RPC error:`)
console.error(error)
return true
},
timeout: 120_000,
})
Expand Down
6 changes: 5 additions & 1 deletion packages/devtools/client/modules/markdown.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import type { BuiltinLanguage } from 'shiki'
import { defineNuxtModule } from '@nuxt/kit'
import { defineNuxtModule, logger } from '@nuxt/kit'
import { consola } from 'consola'
import LinkAttributes from 'markdown-it-link-attributes'
import { createHighlighter } from 'shiki'
import { bundledLanguages } from 'shiki/langs'
import Markdown from 'unplugin-vue-markdown/vite'

export default defineNuxtModule({
async setup(_, nuxt) {
logger.restoreAll()
consola.restoreAll()

nuxt.options.imports.transform ||= {}
nuxt.options.imports.transform.include = [/\.vue$/, /\.md$/]

Expand Down
22 changes: 20 additions & 2 deletions packages/devtools/src/server-rpc/server-data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,24 @@ export function setupServerDataRPC({
let viteServer: ResolvedConfig | undefined
let viteClient: ResolvedConfig | undefined

// Avoid sending the Vite instance to the client
function normalizeViteConfig(config: ResolvedConfig) {
return {
...config,
environments: Object.fromEntries(
Object.entries(config.env).map(([key, _]) => {
return [key, null]
}),
),
plugins: config.plugins.map((i) => {
const clone = { ...i }
delete clone.api
return clone
}),
inlineConfig: null,
} as any as ResolvedConfig
}

nuxt.hook('nitro:build:before', (_nitro) => {
nitro = _nitro
})
Expand All @@ -21,7 +39,7 @@ export function setupServerDataRPC({
name: 'nuxt:devtools:config-retriever',
enforce: 'post',
configResolved(config) {
viteServer = config
viteServer = normalizeViteConfig(config)
},
})
}
Expand All @@ -31,7 +49,7 @@ export function setupServerDataRPC({
name: 'nuxt:devtools:config-retriever',
enforce: 'post',
configResolved(config) {
viteClient = config
viteClient = normalizeViteConfig(config)
},
})
}
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pnpm-workspace.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ catalog:
'@vueuse/nuxt': ^12.5.0
'@xterm/addon-fit': ^0.10.0
'@xterm/xterm': ^5.5.0
birpc: ^2.0.19
birpc: ^2.2.0
bumpp: ^10.0.1
consola: ^3.4.0
conventional-changelog-cli: ^5.0.0
Expand Down

0 comments on commit 9033ce2

Please sign in to comment.