Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rvfakie opened this issue Oct 30, 2024 · 0 comments

Comments

@rvfakie
Copy link

rvfakie commented Oct 30, 2024

Environment

  • Operating System: Darwin
  • Node Version: v20.11.1
  • Nuxt Version: 3.13.2
  • CLI Version: 3.15.0
  • Nitro Version: 2.9.7
  • Package Manager: npm@10.2.4
  • Builder: -
  • User Config: default
  • Runtime Modules: @nuxtjs/i18n@8.5.5, @pinia/nuxt@0.6.0
  • Build Modules: -

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant