generateMetadata() renders <title> and <meta name="description"> inside <body> instead of <head> when using dynamic values #79238
Replies: 4 comments 9 replies
-
Got any reproduction repository? You can see here, https://stackblitz.com/edit/nextjs-utdjj8lk?file=app%2Flayout.tsx that it works fine. |
Beta Was this translation helpful? Give feedback.
-
Convert generateMetadata to synchronous by fetching data directly inside it (avoid async/await). update code via this code 👎 import { Metadata } from "next"; export async function generateMetadata(): Promise { async function getPageInfo() { export default function Page() { Content of the Page ;} changes in code 👎 The title and description are returned as static values if pageInfo is undefined, avoiding async rendering issues. |
Beta Was this translation helpful? Give feedback.
-
TL;DR A quick one, hope it helps you.
|
Beta Was this translation helpful? Give feedback.
-
check this : Moved all metadata configurations to the metadata export. Set metadataBase to ensure relative URLs work correctly. import type { Metadata } from "next"; export const metadata: Metadata = { export default function RootLayout({ |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
We are using generateMetadata() in a Next.js App Router project to dynamically set the page <title> and meta . However, we’ve observed that when returning dynamic values (fetched via an async call), both tags are rendered inside the body, not the head.
If we instead return static string values, they render correctly inside head.
Example code:
Expected behavior:
<title> and description tag should always render in head regardless of static or dynamic values.
Observed behavior:
When values are fetched dynamically (even non-empty), the tags are rendered inside body.
With hardcoded static values, they correctly render inside head.
Additional context:
We are using the App Router with a correct layout structure.
No "use client" directive is present in either app/layout.tsx or app/{path}/layout.tsx.
The root app/layout.tsx defines the , , and elements as recommended.

Beta Was this translation helpful? Give feedback.
All reactions