Closed amannn closed 3 weeks ago
The following PRs will resolve this:
More details: https://github.com/amannn/next-intl/pull/1391
Is this resolved with the canary version of next-intl? I am still getting
Server In route /[locale] headers were iterated over. `headers()` should be awaited before using its value. Learn more: https://nextjs.org/docs/messages/sync-dynamic-apis
Please see here: https://github.com/amannn/next-intl/pull/1391
Please see here: #1391
Hey thanks for the reply! I am unfortunately still having that error after making the changes
Adopting createNavigation and await requestLocale will get your app in shape for Next.js 15 to work without any warnings (see https://github.com/amannn/next-intl/issues/1375).
Will the new canary release on that PR solve the problem?
Also I am still really confused by the approach of adding unstable_setRequestLocale(locale);
everywhere in server layout and pages, will this still be the case in the next js 15 compatible version of next-intl
? Thank you!
@tonyabracadabra Did you upgrade to the new APIs in the canary version? (see also https://github.com/amannn/next-intl/pull/1391#issuecomment-2411017222)
I tried recently with a Next.js 15 canary version and was able to get rid of all warnings. Can you try to diagnose where exactly you're seeing a warning and what causes it?
Also I am still really confused by the approach of adding
unstable_setRequestLocale(locale);
everywhere in server layout and pages, will this still be the case in the next js 15 compatible version ofnext-intl
? Thank you!
That's unfortunately a different story, see https://github.com/amannn/next-intl/issues/663
@amannn Have you seen https://github.com/vercel/next.js/discussions/58862#discussioncomment-10843594?
@imranbarbhuiya Yep, we had a brief exchange on X: https://x.com/jamannnnnn/status/1842179418657116244. It's essentially the same approach as unstable_setRequestLocale
, but in the case of nuqs, parsing is applied on top.
@danielkoller I can't really see an issue in that code sample you've provided. Maybe the error is triggered by another component? I'll soon have the examples in this repo updated for Next.js 15, maybe that can help for reference.
Next.js 15 is supported now without warnings:
await requestLocale
and createNavigation
However, please consider: https://github.com/amannn/next-intl/issues/1442. Due to this, I'm waiting for now with updating examples and the official bug repro.
Is your feature request related to a problem? Please describe.
Ref.: https://github.com/vercel/next.js/pull/68812
next-intl
currently relies on reading a request header to detect the current locale when relevant APIs are called in a Server Component. Note that this by itself is a workaround, ideally the locale could be retrieved from a param (see https://github.com/vercel/next.js/discussions/58862).The APIs
next-intl
offers can be put in three categories:useTranslations
&useFormatter
)useLocale
)Link
—these are lightweight wrappers for navigation APIs from Next.js and automatically incorporate localization of pathnames like locale prefixes)The first two categories use APIs that have signatures that are either hooks or awaitable async functions—so those should be fine to update.
In the third category, the APIs are a bit more diverse. However, most APIs can be adapted as necessary:
Link
component can be turnedasync
to useawait getLocale()
internallyuseRouter
&usePathname
can consume a promise viause
getPathname
requires an explicit locale anywayOnly one API stands out as problematic:
redirect
This is a function that can be called in the following environments:
async
componentasync
componentSince
use(…)
doesn't work inasync
components, we'd have to use an awaitable API for (1). However, for the other call sites, a non-awaitable API would be more ergonomic (otherwise the user would have to wrap inuse
)Describe the solution you'd like
I can think of the following solutions to address this:
redirect
:redirect({locale: 'en', href: '/about'})
. To retrieve the locale, it'd be the job of the user to either callasync getLocale()
oruseLocale()
depending on the calling component.redirect('/about')
redirect
awaitablelocale
(mostly)Another implication is likely that the user can't read the
locale
that's passed toi18n/request.ts
synchronously. We might have to replace this with something promise-based (await locale
orawait getLocale()
).Moving forward
As matters stand currently, it seems like (1) will be more future-proof. Also, in case
use()
becomes available in async Server Components in the future, we can put back a default for the current locale in a later release.Note that the navigation APIs are currently being reworked in https://github.com/amannn/next-intl/pull/1316, so now would be a good point to adjust for the future.