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", "h3": "^1.6.4",
"hookable": "^5.5.3", "hookable": "^5.5.3",
"jiti": "^1.18.2", "jiti": "^1.18.2",
"klona": "^2.0.6",
"knitwork": "^1.0.0", "knitwork": "^1.0.0",
"local-pkg": "^0.4.3", "local-pkg": "^0.4.3",
"magic-string": "^0.30.0", "magic-string": "^0.30.0",

View File

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

View File

@ -614,6 +614,9 @@ importers:
jiti: jiti:
specifier: ^1.18.2 specifier: ^1.18.2
version: 1.18.2 version: 1.18.2
klona:
specifier: ^2.0.6
version: 2.0.6
knitwork: knitwork:
specifier: ^1.0.0 specifier: ^1.0.0
version: 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"') expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"92.4k"')
const modules = await analyzeSizes('node_modules/**/*', serverDir) const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2654k"') expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2657k"')
const packages = modules.files const packages = modules.files
.filter(m => m.endsWith('package.json')) .filter(m => m.endsWith('package.json'))
@ -79,6 +79,7 @@ describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.e
"h3", "h3",
"hookable", "hookable",
"iron-webcrypto", "iron-webcrypto",
"klona",
"node-fetch-native", "node-fetch-native",
"ofetch", "ofetch",
"ohash", "ohash",