amannn / next-intl

🌐 Internationalization (i18n) for Next.js
https://next-intl-docs.vercel.app
MIT License
2.58k stars 236 forks source link

feat!: Require `NextIntlClientProvider` for using `useLocale` on the client side (preparation for `dynamicIO`) #1541

Closed amannn closed 2 days ago

amannn commented 3 days ago

tldr; β€” Do you already have a NextIntlClientProvider in your root layout that wraps all components? If yes, you can skip this.


Previously, useParams().locale was consulted when reading from useLocale() on the client side, allowing to use this API even when no NextIntlClientProvider is used.

This behavior has now been removed because:

  1. Reading from useParams().locale doesn't apply if you're using an App Router setup without i18n routing.
  2. Reading from useParams() might require additional work from the developer in the future to work with the upcoming dynamicIO rendering mode like adding 'use cache' or a <Suspense /> boundary.

Therefore, if you use any features from next-intl on the client side, you should now add a NextIntlClientProvider in the root layout and wrap all relevant components:

import {NextIntlClientProvider} from 'next-intl';

export default async function LocaleLayout(/* ... */) {
  // ...

  return (
    <html lang={locale}>
      <body>
        <NextIntlClientProvider>
          {children}
        </NextIntlClientProvider>
      </body>
    </html>
  );
}

Note that also navigation APIs like Link rely on useLocale internally.

vercel[bot] commented 3 days ago

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
next-intl-docs βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 14, 2024 2:13pm
next-intl-example-app-router βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 14, 2024 2:13pm
next-intl-example-app-router-without-i18n-routing βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback Nov 14, 2024 2:13pm