From 9e56b60c6b948596d29f153a0ef002ee04d5c067 Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Wed, 12 Jun 2024 12:39:40 +0100 Subject: [PATCH] fix(nuxt): only log warning once per `runtimeConfig` key --- packages/nuxt/src/app/nuxt.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/nuxt/src/app/nuxt.ts b/packages/nuxt/src/app/nuxt.ts index 03f08213e4..8839005f3b 100644 --- a/packages/nuxt/src/app/nuxt.ts +++ b/packages/nuxt/src/app/nuxt.ts @@ -558,6 +558,7 @@ export function defineAppConfig (config: C): C { /** * Configure error getter on runtime secret property access that doesn't exist on the client side */ +const loggedKeys = new Set() function wrappedConfig (runtimeConfig: Record) { if (!import.meta.dev || import.meta.server) { return runtimeConfig } const keys = Object.keys(runtimeConfig).map(key => `\`${key}\``) @@ -565,7 +566,10 @@ function wrappedConfig (runtimeConfig: Record) { 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) },