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

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