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

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

Merged
merged 24 commits into from
Nov 14, 2024

Conversation

amannn
Copy link
Owner

@amannn amannn commented Nov 13, 2024

tldr; — Do you already have a NextIntlClientProvider in your root layout that wraps all Client 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 ancestor is available.

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 make sure that a NextIntlClientProvider wraps all relevant components (typically in the root layout):

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.

Copy link

vercel bot commented Nov 13, 2024

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

@amannn amannn changed the title feat!: Don't read a default for locale from useParams.locale on the client side feat!: Don't read a default for locale from useParams.locale on the client side, but rely on NextIntlClientProvider being used Nov 13, 2024
@amannn amannn changed the title feat!: Don't read a default for locale from useParams.locale on the client side, but rely on NextIntlClientProvider being used feat!: Require NextIntlClientProvider for using next-intl in Client Components Nov 14, 2024
@amannn amannn changed the title feat!: Require NextIntlClientProvider for using next-intl in Client Components feat!: Require NextIntlClientProvider when using next-intl in Client Components Nov 14, 2024
@amannn amannn changed the title feat!: Require NextIntlClientProvider when using next-intl in Client Components feat!: Don't read a default for locale from useParams.locale on the client side, but rely on NextIntlClientProvider being used (preparation for dynamicIO) Nov 14, 2024
@amannn amannn changed the title feat!: Don't read a default for locale from useParams.locale on the client side, but rely on NextIntlClientProvider being used (preparation for dynamicIO) feat!: Don't read a default for useLocale from useParams.locale on the client side, but rely on NextIntlClientProvider being used (preparation for dynamicIO) Nov 14, 2024
# Conflicts:
#	docs/src/pages/docs/usage/configuration.mdx
@amannn amannn merged commit dc36097 into v4 Nov 14, 2024
3 of 5 checks passed
@amannn amannn deleted the feat/dio-no-params branch November 14, 2024 14:11
@amannn amannn changed the title feat!: Don't read a default for useLocale from useParams.locale on the client side, but rely on NextIntlClientProvider being used (preparation for dynamicIO) feat!: Require NextIntlClientProvider for using useLocale on the client side (preparation for dynamicIO) Nov 15, 2024
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.

1 participant