Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4133 pages
Next.js and React

The title and meta tags from generateMetadata show up inside <body>

Your error

<title> and <meta name="description"> appear after <body> in view-source2 more lines it can show

Fix it fast

Most common cause, 1 of 3

generateMetadata depends on request-time data, so it is streamed

If your target crawlers run JavaScript, nothing needs fixing.

Fix
// next.config.js
module.exports = {
  htmlLimitedBots: /.*/,
}
Did this fix it?
Full steps for this cause: check, fix, verify

Short answer

This is streaming metadata, added in Next.js 15.2. When generateMetadata waits on request-time data, Next.js sends the page first and appends the tags to <body> once they resolve. Bots that run JavaScript, such as Googlebot, read them from the DOM; HTML-only bots get them in <head>. To force <head> for everyone, set htmlLimitedBots: /.*/ or make the metadata static.

  • Applies to Next.js 15.5, React 19, Node.js 24
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Which cause do you have?

Fetch the same URL with two user agents and see where the title lands. A difference between them means streaming metadata, not a bug in your layout.

Run this first
curl -s -A "Mozilla/5.0 Chrome/131" https://example.com/page | grep -o '<title>[^<]*'
curl -s -A "facebookexternalhit/1.1" https://example.com/page | grep -o '<title>[^<]*'

Then find the line you see in this list and open its fix:

  1. 1generateMetadata depends on request-time data, so it is streamedBrowsers and Googlebot get the tags after <body>; facebookexternalhit gets them in <head>
  2. 2A crawler you care about is missing from the default bot listOne social preview or SEO tool shows no title while Google and Facebook show it
  3. 3The page could be static, but the metadata makes it dynamicThe route shows as dynamic (ƒ) in next build only because generateMetadata reads cookies, headers or searchParams

What does the error look like?

  • <title> and <meta name="description"> appear after <body> in view-source
  • Meta tags are moving to the <body> tag instead of the <head> tag
  • An SEO checker says the page has no title or description in the head

Cause 1 of 3

generateMetadata depends on request-time data, so it is streamed

You seeBrowsers and Googlebot get the tags after <body>; facebookexternalhit gets them in <head>

Check

Find the generateMetadata of that route and see whether it awaits cookies(), headers(), searchParams or uncached data. If it does, the response starts before the tags exist, so they arrive later inside the body. Crawlers that execute JavaScript read them from the finished DOM; HTML-limited crawlers are made to wait and get them in the head.

Check
grep -rnE "generateMetadata|cookies\(|headers\(|searchParams" app --include=page.* --include=layout.*

Fix

If your target crawlers run JavaScript, nothing needs fixing. If a tool you rely on does not, disable streaming for every user agent with the htmlLimitedBots option (Next.js 15.2.0 or later).

Fix
// next.config.js
module.exports = {
  htmlLimitedBots: /.*/,
}

Verify

Rebuild and fetch the page as a normal browser; the title now comes before <body>.

Verify
curl -s -A 'Mozilla/5.0 Chrome/131' http://localhost:3000/page | grep -o '<title>[^<]*'

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 3

A crawler you care about is missing from the default bot list

You seeOne social preview or SEO tool shows no title while Google and Facebook show it

Check

Next.js ships a default list of HTML-limited bots. A custom value replaces that list rather than adding to it, so a pattern that names only your extra bot drops the defaults.

Check
grep -n htmlLimitedBots next.config.*

Fix

Write a pattern that covers your extra user agent and the crawlers you still need, or use /.*/ if you prefer blocking metadata for everyone.

Fix
module.exports = {
  htmlLimitedBots: /facebookexternalhit|Twitterbot|LinkedInBot|Slackbot|MyCrawler/,
}

Verify

Fetch the page with that crawler's user agent string and confirm the tags sit in the head.

Verify
curl -s -A 'MyCrawler/1.0' http://localhost:3000/page | grep -o '<title>[^<]*'

Confirmed by nextjs.org

Did this fix it?

Cause 3 of 3

The page could be static, but the metadata makes it dynamic

You seeThe route shows as dynamic (ƒ) in next build only because generateMetadata reads cookies, headers or searchParams

Check

A prerendered page whose generateMetadata adds no request-time behaviour has its tags baked into the first HTML. Removing the one headers() or cookies() call is often enough to turn the route from ƒ into ○ in the build output.

Check
npx next build | grep -E '○|ƒ'

Fix

Build the metadata from params and cached data only, or use the static metadata object when the values do not change per request.

Fix
// app/about/page.tsx
export const metadata = {
  title: 'About',
  description: 'What this site is about.',
}

Verify

next build lists the route as static, and the title is inside the head of the built HTML.

Verify
curl -s http://localhost:3000/about | grep -o '<title>[^<]*'

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Keep generateMetadata free of cookies() and headers() unless the tags really differ per visitor.
  • Test social previews with the platform's own debugger after each Next.js upgrade.
  • Check view-source and the rendered DOM separately; streamed tags only exist in the second.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.