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

Cookie Value Error #2822

Closed
Fiyuva opened this issue Feb 29, 2024 · 10 comments · Fixed by #2841
Closed

Cookie Value Error #2822

Fiyuva opened this issue Feb 29, 2024 · 10 comments · Fixed by #2841
Labels
🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage v8

Comments

@Fiyuva
Copy link

Fiyuva commented Feb 29, 2024

Environment

  • Nuxt Version: 3.10.3
  • CLI Version: 3.10.1
  • Nitro Version: 2.8.1

Reproduction

i18n: {
baseUrl: process.env.BASE_URL,
langDir: "locales/",
strategy: "no_prefix",
skipSettingLocaleOnNavigate: true,
defaultDirection: "ltr",
defaultLocale: "tr",
detectBrowserLanguage: {
useCookie: true,
fallbackLocale: "tr",
alwaysRedirect: true,
cookieSecure: true,
redirectOn: "root",
cookieKey: "lng"
},
locales: [
{
code: "tr",
iso: "tr-TR",
name: "Türkçe",
file: "tr.json",
dir: "ltr"
},
{
code: "en",
iso: "en-US",
name: "English",
file: "en.json",
dir: "ltr"
}
]
}

Describe the bug

I work with 2 languages, En and Tr, and I use cookies. It works great when my cookie value is en or tr, but when I change the cookie value manually, it should be tr but it doesn't work. What is my mistake?

i18n: {
baseUrl: process.env.BASE_URL,
langDir: "locales/",
strategy: "no_prefix",
skipSettingLocaleOnNavigate: true,
defaultDirection: "ltr",
defaultLocale: "tr",
detectBrowserLanguage: {
useCookie: true,
fallbackLocale: "tr",
alwaysRedirect: true,
cookieSecure: true,
redirectOn: "root",
cookieKey: "lng"
},
locales: [
{
code: "tr",
iso: "tr-TR",
name: "Türkçe",
file: "tr.json",
dir: "ltr"
},
{
code: "en",
iso: "en-US",
name: "English",
file: "en.json",
dir: "ltr"
}
]
}

Additional context

No response

Logs

No response

Copy link

github-actions bot commented Mar 2, 2024

Would you be able to provide a reproduction? 🙏

More info

Why do I need to provide a reproduction?

Reproductions make it possible for us to triage and fix issues quickly with a relatively small team. It helps us discover the source of the problem, and also can reveal assumptions you or we might be making.

What will happen?

If you've provided a reproduction, we'll remove the label and try to reproduce the issue. If we can, we'll mark it as a bug and prioritise it based on its severity and how many people we think it might affect.

If needs reproduction labeled issues don't receive any substantial activity (e.g., new comments featuring a reproduction link), we'll close them. That's not because we don't care! At any point, feel free to comment with a reproduction and we'll reopen it.

How can I create a reproduction?

We have a couple of templates for starting with a minimal reproduction:

👉 Reproduction starter (v8 and higher)
👉 Reproduction starter (edge)

A public GitHub repository is also perfect. 👌

Please ensure that the reproduction is as minimal as possible. See more details in our guide.

You might also find these other articles interesting and/or helpful:

@Fiyuva
Copy link
Author

Fiyuva commented Mar 2, 2024

image
image

I tried to reproduce it but failed, so I showed it as a picture.

When the user sets the cookie value to a random value as in the picture and refreshes the page, it does not return to the default value.

If the cookie value is en or tr, the system works perfectly.

The part I don't understand here is why the default doesn't work when the user manually changes the cookie value.

@BobbieGoede
Copy link
Collaborator

Based on your description it doesn't sound like a bug, of course editing cookies by hand to unexpected values will result in undefined behaviour.

That said, I can see this happen in an edge case which could happen when a website removes a language which previously would have been saved in a cookie. In such cases it would make sense to redirect/fallback to the default language.

I tried to reproduce it but failed, so I showed it as a picture.

Did you try making it using stackblitz? You may need to open the preview in a new tab for the cookies to work. Even if I understood the issue correctly a reproduction would be useful for me to test a solution on (and add tests for it).

@BobbieGoede BobbieGoede added 🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage v8 and removed pending triage need reproduction 💻 labels Mar 3, 2024
@Fiyuva
Copy link
Author

Fiyuva commented Mar 3, 2024

I think I did.

https://stackblitz.com/edit/github-kvjw8r-jgxyrr?file=nuxt.config.ts

When the cookie value is changed manually, it does not return to the default value. How can I solve this problem?

@Fiyuva
Copy link
Author

Fiyuva commented Mar 14, 2024

any update?

@BobbieGoede
Copy link
Collaborator

Unfortunately I was busy with other issues and my day job, will look into this when I have the time.

@BobbieGoede
Copy link
Collaborator

BobbieGoede commented Mar 17, 2024

With #2841 merged the locale cookie should revert to the defaultLocale if configured (or undefined if not) if the locale cookie does not match any configured locales.

You can try it out on the edge channel (npm i -D @nuxtjs/i18n@npm:@nuxtjs/i18n npm i -D @nuxtjs/i18n@npm:@nuxtjs/i18n-edge), let me know if you run into any issues!

@Fiyuva
Copy link
Author

Fiyuva commented Mar 17, 2024

I did the following steps.

1- npm i -D @nuxtjs/i18n@npm:@nuxtjs/i18n

2- I changed the cookie value to an irrelevant value and refreshed the page. I got the results in the picture above.

I checked what you wrote, but I couldn't correct the mistake. DefaultLocale doesn't seem to be working or I couldn't do it.

@BobbieGoede
Copy link
Collaborator

Oh I'm sorry, I made a mistake in the install command 😥 it should be npm i -D @nuxtjs/i18n@npm:@nuxtjs/i18n-edge.

@Fiyuva
Copy link
Author

Fiyuva commented Mar 17, 2024

My problem is solved. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 p3-minor-bug Priority 3: a bug in an edge case that only affects very specific usage v8
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants