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

Is it possible to opt out from using cookies or headers? #366

Closed
mattiaz9 opened this issue Feb 26, 2024 · 4 comments
Closed

Is it possible to opt out from using cookies or headers? #366

mattiaz9 opened this issue Feb 26, 2024 · 4 comments
Labels
enhancement New feature or request

Comments

@mattiaz9
Copy link

Is your feature request related to a problem? Please describe.

Right now it gives me the error Locale not found in headers or cookies, returning "notFound()", most likely because I'm not using the default middleware implementation.
I don't want to use cookies or headers, since this will cause next to opt out from page caching.

Describe the solution you'd like

using setStaticParamsLocale in the root layout would be great. When I tried it didn't work. Maybe this is an issue?

Describe alternatives you've considered

--

Additional context

I'm using nextjs 14 with the app router and server components.

@mattiaz9 mattiaz9 added the enhancement New feature or request label Feb 26, 2024
@zfm-lucaschultz
Copy link

Hi, we had the same issue and solved it by using a custom middleware which gets the locale and adds it to the request using a copied and pasted version of addLocaleToResponse. This might lead to other side effects, though.

Overall, I think it would be great to add proper support for this. As I see it, this might not actually need a lot of changes (if any) in the implementation of at least the app router part of this package, but is merely a question of adding documentation and exporting addLocaleToResponse. I may be wrong, though. What do you think, @QuiiBz?

@mattiaz9
Copy link
Author

@zfm-lucaschultz isn't that the same?
I mean, if you set the locale in the middleware then you need to access cookies or headers in the page anyway.

What I need is to set the locale directly in the root layout.

Or am I missing something here?

@mattiaz9
Copy link
Author

I ended up creating a custom implementation that uses https://github.com/manvalls/server-only-context on the server to store the current locale and translations

@QuiiBz
Copy link
Owner

QuiiBz commented Feb 27, 2024

Using setStaticParamsLocale in the root layout would be great. When I tried it didn't work. Maybe this is an issue?

You have to call setStaticParamsLocale() in every page that you want to be static: see https://next-international.vercel.app/docs/app-static-rendering#static-rendering

I'm curious to know why you had to use another middleware implementation?

@QuiiBz QuiiBz closed this as not planned Won't fix, can't repro, duplicate, stale Feb 27, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants