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

fix: Correctly detect base path at the app root / when using a locale prefix strategy other than always. This ensures the locale cookie is set correctly. #999

Merged
merged 1 commit into from
Apr 17, 2024

Conversation

amannn
Copy link
Owner

@amannn amannn commented Apr 17, 2024

Fixes #997

@amannn amannn marked this pull request as ready for review April 17, 2024 11:09
Copy link

vercel bot commented Apr 17, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
next-intl-docs ✅ Ready (Inspect) Visit Preview Apr 17, 2024 11:09am
next-intl-example-app-router ✅ Ready (Inspect) Visit Preview Apr 17, 2024 11:09am

@amannn amannn changed the title fix: Correctly detect base path at the app root / when using a locale prefix strategy other than always fix: Correctly detect base path at the app root / when using a locale prefix strategy other than always. This ensures the locale cookie is set correctly. Apr 17, 2024
@amannn amannn merged commit 1ce5988 into main Apr 17, 2024
6 checks passed
@amannn amannn deleted the fix/997-fix-base-path-without-prefix branch April 17, 2024 11:18
@130db
Copy link

130db commented Jul 18, 2024

Interesting!
Can not upgrade to 3.11.2 or higher after this fix.

Here is my autogenerated config.
Screenshot 2024-07-18 at 20 06 01

const locales is not casted with "as const" because line 9 will fail in i18n.ts

Screenshot 2024-07-18 at 20 08 16

@akhlivniukallane
Copy link

We experience the same problem with the same config parameters as above.
cc @amannn any idea? It looks like some basic misconfiguration, but where..

@130db
Copy link

130db commented Sep 10, 2024

Yes! I fixed it.

Tried different approach by following Mohammad's tutorial
https://phrase.com/blog/posts/next-js-app-router-localization-next-intl/

Did POC on fresh NextJS install and then tried to replicate on my website.
Guess what, it failed :D with

TypeError [ERR_INVALID_STATE]: Invalid state: ReadableStream is already closed

The problem is:
When you use async page and call await getTranslations it fails.

Solution
Make page non-async and replace getTranslations with useTranslations
Move every other await to coresponding component

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

Successfully merging this pull request may close these issues.

Locale change issue with basePath and localePrefix = 'as-needed'
3 participants