Skip to content

Commit

Permalink
fix(nuxt): only log warning once per runtimeConfig key
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jun 12, 2024
1 parent b17aa3f commit 9e56b60
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/nuxt/src/app/nuxt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,14 +558,18 @@ export function defineAppConfig<C extends AppConfigInput> (config: C): C {
/**
* Configure error getter on runtime secret property access that doesn't exist on the client side
*/
const loggedKeys = new Set<string>()
function wrappedConfig (runtimeConfig: Record<string, unknown>) {
if (!import.meta.dev || import.meta.server) { return runtimeConfig }
const keys = Object.keys(runtimeConfig).map(key => `\`${key}\``)
const lastKey = keys.pop()
return new Proxy(runtimeConfig, {
get (target, p, receiver) {
if (typeof p === 'string' && p !== 'public' && !(p in target) && !p.startsWith('__v') /* vue check for reactivity, e.g. `__v_isRef` */) {
console.warn(`[nuxt] Could not access \`${p}\`. The only available runtime config keys on the client side are ${keys.join(', ')} and ${lastKey}. See \`https://nuxt.com/docs/guide/going-further/runtime-config\` for more information.`)
if (!loggedKeys.has(p)) {
loggedKeys.add(p)
console.warn(`[nuxt] Could not access \`${p}\`. The only available runtime config keys on the client side are ${keys.join(', ')} and ${lastKey}. See \`https://nuxt.com/docs/guide/going-further/runtime-config\` for more information.`)
}
}
return Reflect.get(target, p, receiver)
},
Expand Down

0 comments on commit 9e56b60

Please sign in to comment.