nuxt-modules / i18n

I18n module for Nuxt
https://i18n.nuxtjs.org
MIT License
1.7k stars 475 forks source link

Warning: Avoid app logic that relies on enumerating keys on a component instance. The keys will be empty in production mode to avoid performance overhead. #2856

Open frasza opened 6 months ago

frasza commented 6 months ago

Environment


Reproduction

https://github.com/frasza/i18n-warn

Spin up dev server, open dev tools and click on NuxtLink. Warning appears.

Describe the bug

Recently I noticed warning popup in my Nuxt project and I have tried to set up fresh Nuxt project with i18n dependacy and I still get warning when for navigating across pages.

Warning:

[Vue warn]: Avoid app logic that relies on enumerating keys on a component instance. The keys will be empty in production mode to avoid performance overhead.

Noticed that I get warning the moment I add i18n to the modules.

Additional context

No response

Logs

No response

BobbieGoede commented 6 months ago

I'm unable to reproduce this using your reproduction, I did have to update Nuxt to 3.11.1 or the dev server wouldn't run. Has this already been resolved?

frasza commented 6 months ago

I still have problem with warning even tho I am on Nuxt 3.11.1.

BobbieGoede commented 6 months ago

Do you get the warning using this updated reproduction? https://stackblitz.com/edit/frasza-i18n-warn-76cwcr?file=nuxt.config.ts

frasza commented 6 months ago

Yeah, I have downloaded the project, run it locally and I still get it 🤔 image

BobbieGoede commented 6 months ago

Ah after running it locally I get the same warning, looks like this happens when you add Nuxt I18n without configuring any locales. The module tries to navigate/redirect to a localized page but there are none, maybe we should add some checks to disable the module if nothing is configured.

frasza commented 6 months ago

Locally I have it configured tho.

i18n: {
    vueI18n: '@/i18n.config.ts',
  },
import en from '@/locales/en.json'
import si from '@/locales/si.json'

export default defineI18nConfig(() => ({
  legacy: false,
  locale: 'si',
  messages: {
    si,
    en,
  },
}))

Perhaps something here wrong as well...

BobbieGoede commented 6 months ago

Let me know if these changes fix it for you:

i18n: {
    vueI18n: '@/i18n.config.ts',
+   locales: ['en', 'si']
+   defaultLocale: ['si']
},
import en from '@/locales/en.json'
import si from '@/locales/si.json'

export default defineI18nConfig(() => ({
   legacy: false,
-  locale: 'si',
   messages: {
     si,
     en,
   },
}))
frasza commented 6 months ago

I see this forces locale in URL paht (e.g.: /si). How can I escape this, since we are not using locales in url pahts?

BobbieGoede commented 6 months ago

Check out the docs on routing strategies https://i18n.nuxtjs.org/docs/guide

frasza commented 6 months ago

Thank you.

Indeed! In this case I do not get warning. Now it is a bit 'weird' that configuration is split between the files but yeah, it seems to be working well.