mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-22 05:35:13 +00:00
fix(nuxt): deprecate old (pre-rc) runtimeConfig (#20082)
This commit is contained in:
parent
6ddea42f96
commit
c65c5a8e79
@ -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') {
|
||||
|
2
test/fixtures/basic/pages/index.vue
vendored
2
test/fixtures/basic/pages/index.vue
vendored
@ -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>
|
||||
|
2
test/fixtures/basic/plugins/async-plugin.ts
vendored
2
test/fixtures/basic/plugins/async-plugin.ts
vendored
@ -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!'
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user