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

I'm having SEO issues with a nextJS app where the meta data is being outputted outside of the body

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.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744200514a4562855.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信