8000 docs: clarify root layout requirements and `suppressHydrationWarning` usage with App Router by boutterudy · Pull Request #1927 · amannn/next-intl · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

docs: clarify root layout requirements and suppressHydrationWarning usage with App Router #1927

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,28 @@ const withNextIntl = createNextIntlPlugin(

</Details>

### `src/app/layout.tsx` [#rootlayout]

<Callout>
<strong>Note on nested `<html>` and `<body>` tags:</strong>

Next.js <strong>requires</strong> `<html>` and `<body>` in `app/layout.tsx`.
If your `[locale]/layout.tsx` also contains them (it usually does so it can set `lang`), the tags are rendered twice and you’ll see hydration warnings in development.

Add `suppressHydrationWarning` to <em>both</em> tags in <strong>both</strong> layouts

</Callout>

```tsx filename="app/layout.tsx"
export default function RootLayout({children}: {children: React.ReactNode}) {
return (
<html suppressHydrationWarning>
<body suppressHydrationWarning>{children}</body>
</html>
);
}
```

### `src/app/[locale]/layout.tsx` [#layout]

The `locale` that was matched by the middleware is available via the `locale` param and can be used to configure the document language. Additionally, we can use this place to pass configuration from `i18n/request.ts` to Client Components via `NextIntlClientProvider`.
Expand All @@ -238,8 +260,8 @@ export default async function LocaleLayout({
}

return (
<html lang={locale}>
<body>
<html lang={locale} suppressHydrationWarning>
<body suppressHydrationWarning>
<NextIntlClientProvider>{children}</NextIntlClientProvider>
</body>
</html>
Expand Down
0