fix(nuxt): clone app config on server (#20278)

This commit is contained in:
Daniel Roe 2023-04-20 13:33:45 +01:00 committed by GitHub
parent 8234bc18d7
commit 12f347a928
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 2 deletions

View File

@ -73,6 +73,7 @@
"h3": "^1.6.4",
"hookable": "^5.5.3",
"jiti": "^1.18.2",
"klona": "^2.0.6",
"knitwork": "^1.0.0",
"local-pkg": "^0.4.3",
"magic-string": "^0.30.0",

View File

@ -1,4 +1,5 @@
import { reactive } from 'vue'
import { klona } from 'klona'
import type { AppConfig } from 'nuxt/schema'
import { useNuxtApp } from './nuxt'
// @ts-expect-error virtual file
@ -37,7 +38,7 @@ function deepAssign (obj: any, newObj: any) {
export function useAppConfig (): AppConfig {
const nuxtApp = useNuxtApp()
if (!nuxtApp._appConfig) {
nuxtApp._appConfig = reactive(__appConfig) as AppConfig
nuxtApp._appConfig = (process.server ? klona(__appConfig) : reactive(__appConfig)) as AppConfig
}
return nuxtApp._appConfig
}

View File

@ -614,6 +614,9 @@ importers:
jiti:
specifier: ^1.18.2
version: 1.18.2
klona:
specifier: ^2.0.6
version: 2.0.6
knitwork:
specifier: ^1.0.0
version: 1.0.0

View File

@ -51,7 +51,7 @@ describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.e
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"92.4k"')
const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2654k"')
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2657k"')
const packages = modules.files
.filter(m => m.endsWith('package.json'))
@ -79,6 +79,7 @@ describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.e
"h3",
"hookable",
"iron-webcrypto",
"klona",
"node-fetch-native",
"ofetch",
"ohash",