nuxt-modules / i18n

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

window.location.reload immediately after nuxtApp.hook('i18n:localeSwitched') not working as expected #3192

Open rvfakie opened 4 weeks ago

rvfakie commented 4 weeks ago

Environment

Reproduction

https://stackblitz.com/edit/github-paob67?file=plugins%2Finit.ts but for some reason stackblitz not setting cookie when using setLocale from useI18n;

Describe the bug

When calling window.location.reload() immediately in callback in nuxtApp.hook('i18n:localeSwitched'), cookie and current language resets to a previous value.

nuxtApp.hook('i18n:localeSwitched', () => window.location.reload());

But if you wrap reload in setTimeout it works as expected

nuxtApp.hook('i18n:localeSwitched', () => {
    setTimeout(() => window.location.reload(), 100);
});

Additional context

If this hook is async we should probably wait for it and then execute our callback?

Logs

No response