最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - NextJS generateMetadata is rendering outside of the <head> tag - Stack Overflow

programmeradmin3浏览0评论

I'm having SEO issues with a nextJS app where the meta data is being outputted outside of the body tag. I have this bit of code in my page.tsx file

export async function generateMetadata(
    { params, searchParams }: Props,
    parent: ResolvingMetadata
): Promise<Metadata> {
    void searchParams;
    void parent;
    const {business, city, category} = await params

    return await generateBusinessMetadata({
        businessSlug: business,
        city: city,
        category: category,
    });
}

inside generateBusinessMeta data there is a supabase data fetch.

Weirdly, if I hard refresh the meta data shows in the head, but when I do a normal refresh it moves down below the script tags at the bottom of the page. This is causing all sorts of issues with SEO, and my impressions have plummeted, any ideas what is going on?

I'm using the app router on Next 15.2.3

I'm having SEO issues with a nextJS app where the meta data is being outputted outside of the body tag. I have this bit of code in my page.tsx file

export async function generateMetadata(
    { params, searchParams }: Props,
    parent: ResolvingMetadata
): Promise<Metadata> {
    void searchParams;
    void parent;
    const {business, city, category} = await params

    return await generateBusinessMetadata({
        businessSlug: business,
        city: city,
        category: category,
    });
}

inside generateBusinessMeta data there is a supabase data fetch.

Weirdly, if I hard refresh the meta data shows in the head, but when I do a normal refresh it moves down below the script tags at the bottom of the page. This is causing all sorts of issues with SEO, and my impressions have plummeted, any ideas what is going on?

I'm using the app router on Next 15.2.3

Share Improve this question asked Mar 25 at 11:23 Elliott CoeElliott Coe 5833 gold badges6 silver badges20 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

This is expected behavior. Next.js 15.2 introduced a new feature called streaming metadata. With this update, metadata is streamed to the UI as and when it becomes available. If you're performing dynamic data fetching or asynchronous operations within generateMetadata, the metadata may not be available when the initial UI is ready. So the UI will be sent to the browser before generateMetadata has completed.

And when the metadata is streamed, it will be placed in the <body> tag.

However, as noted in the blog post, this will not impact SEO. Search engine bots and crawlers will receive the HTML only after the metadata has been fully generated.

You can configure the user agents which should receive the blocking metadata using the htmlLimitedBots config.

发布评论

评论列表(0)

  1. 暂无评论