Next/Head empty on first render using getServerSideProps
See original GitHub issueBug report
It’s very possible I’m going nuts on this or that I’m misunderstanding something basic, so apologies in advance!
I’m using Next/head to render SEO metatags on _app.js
and various dynamic page components. When I check the rendered elements in the Chrome debugger, all the proper tags are there. When I look at the source and I check via facebook checker, none of the meta tags are present.
I’m wondering if I’m missing an understanding of how Next/Head is supposed to be used, or something in the rendering pipeline for next?
Describe the bug
Next/Head is failing to render metatags in _app and pages.
These pages use getServerSideProps
Here’s an example of the Head tag for the below example
<Head>
<title>{props.username}'s Fits on Stupid Fits</title>
<meta
property="og:title"
content={`${props.username}'s Fits on Stupid Fits`}
key="title"
/>
<meta
property="og:url"
content={`${process.env.HOST}/u/${props.username}`}
key="url"
/>
<meta property="og:type" content="profile" />
<meta property="profile:username" content={props.username} />
</Head>
To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
Example rendering: Facebook Scraper Source (in Chrome) Original page
Page is rendered using getServerSideProps
Expected behavior
Server should render <head>
contents at point of request so that contents can be scraped for SEO purposes
Screenshots
System information
- Version of Next.js: 9.5.5
- Version of Node.js: >=14.13.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
Update: I have located my problem. I had wrapped all content with an if clause in _app.ts, to defer content render until user data is loaded and render
Loading...
until then. Thus crawlers only ever got that HTML. 😌This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.