Skip to content

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
amannn merged 1 commit into
mainfrom
fix/997-fix-base-path-without-prefix
Apr 17, 2024
Merged

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
amannn merged 1 commit into
mainfrom
fix/997-fix-base-path-without-prefix

Conversation

@amannn

@amannn amannn commented Apr 17, 2024

Copy link
Copy Markdown
Owner

Fixes #997

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

vercel Bot commented Apr 17, 2024

Copy link
Copy Markdown

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
@amannn
amannn deleted the fix/997-fix-base-path-without-prefix branch April 17, 2024 11:18
@130db

130db commented Jul 18, 2024

Copy link
Copy Markdown

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

@ghost

ghost commented Sep 10, 2024

Copy link
Copy Markdown

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

130db commented Sep 10, 2024

Copy link
Copy Markdown

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

juanforlizzi pushed a commit to juanforlizzi/next-intl that referenced this pull request Jan 16, 2025
…le prefix strategy other than `always`. This ensures the locale cookie is set correctly. (amannn#999)

Fixes amannn#997
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'

2 participants