fix(nuxt): remove backwards-compatible runtimeConfig proxy (#20340)

This commit is contained in:
Daniel Roe 2023-04-29 23:38:40 +01:00 committed by GitHub
parent cd7f38988a
commit 6ef2e1caea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 26 deletions

View File

@ -281,30 +281,7 @@ export function createNuxtApp (options: CreateOptions) {
// Expose runtime config
const runtimeConfig = process.server ? options.ssrContext!.runtimeConfig : reactive(nuxtApp.payload.config)
// TODO: remove in v3.5
// Backward compatibility following #4254
const compatibilityConfig = new Proxy(runtimeConfig, {
get (target, prop: string) {
if (prop in target) {
return target[prop]
}
if (process.dev && prop in target.public) {
console.warn(`[nuxt] [runtimeConfig] You are trying to access a public runtime config value (\`${prop}\`) directly from the top level. This currently works (for backward compatibility with Nuxt 2) but this compatibility layer will be removed in v3.5. Instead, you can update \`config['${prop}']\` to \`config.public['${prop}']\`.`)
}
return target.public[prop]
},
set (target, prop, value) {
if (process.server || prop === 'public' || prop === 'app') {
return false // Throws TypeError
}
target[prop] = value
target.public[prop] = value
return true
}
})
nuxtApp.provide('config', compatibilityConfig)
nuxtApp.provide('config', runtimeConfig)
return nuxtApp
}

View File

@ -34,7 +34,7 @@ describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.e
it('default client bundle size', async () => {
stats.client = await analyzeSizes('**/*.js', publicDir)
expect(roundToKilobytes(stats.client.totalBytes)).toMatchInlineSnapshot('"94.2k"')
expect(roundToKilobytes(stats.client.totalBytes)).toMatchInlineSnapshot('"94.0k"')
expect(stats.client.files.map(f => f.replace(/\..*\.js/, '.js'))).toMatchInlineSnapshot(`
[
"_nuxt/entry.js",
@ -45,7 +45,7 @@ describe.skipIf(isWindows || process.env.TEST_BUILDER === 'webpack' || process.e
it('default server bundle size', async () => {
stats.server = await analyzeSizes(['**/*.mjs', '!node_modules'], serverDir)
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"66.8k"')
expect(roundToKilobytes(stats.server.totalBytes)).toMatchInlineSnapshot('"66.6k"')
const modules = await analyzeSizes('node_modules/**/*', serverDir)
expect(roundToKilobytes(modules.totalBytes)).toMatchInlineSnapshot('"2654k"')