fix(nuxt): deprecate old (pre-rc) runtimeConfig (#20082)

This commit is contained in:
Daniel Roe 2023-04-07 12:36:45 +01:00 committed by GitHub
parent 6ddea42f96
commit c65c5a8e79
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 9 deletions

View File

@ -255,17 +255,19 @@ export function createNuxtApp (options: CreateOptions) {
}
// Expose runtime config
const runtimeConfig = process.server
? options.ssrContext!.runtimeConfig
: reactive(nuxtApp.payload.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) {
if (prop === 'public') {
return target.public
get (target, prop: string) {
if (prop in target) {
return target[prop]
}
return target[prop] ?? target.public[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') {

View File

@ -4,7 +4,7 @@
<Title>Basic fixture</Title>
</Head>
<h1>Hello Nuxt 3!</h1>
<div>RuntimeConfig | testConfig: {{ config.testConfig }}</div>
<div>RuntimeConfig | testConfig: {{ config.public.testConfig }}</div>
<div>Composable | foo: {{ foo }}</div>
<div>Composable | bar: {{ bar }}</div>
<div>Composable | template: {{ templateAutoImport }}</div>

View File

@ -6,7 +6,7 @@ export default defineNuxtPlugin(async (/* nuxtApp */) => {
return {
provide: {
asyncPlugin: () => config1 && config1 === config2
? 'Async plugin works! ' + config1.testConfig + (data.value?.baz ? 'useFetch works!' : 'useFetch does not work')
? 'Async plugin works! ' + config1.public.testConfig + (data.value?.baz ? 'useFetch works!' : 'useFetch does not work')
: 'Async plugin failed!'
}
}