Commit 04cf7797 authored by Gerald Monaco's avatar Gerald Monaco Committed by Joe Haddad

Add warning for missing <Head> (#8276)

* Add warning for missing <Head>

* Update the warning to be eliminated away in production

* Update head-manager.js
parent 3eca8860
# `next-head-count` is missing
#### Why This Error Occurred
You have a custom `pages/_document.js` that doesn't have the components required for Next.js to render correctly.
#### Possible Ways to Fix It
Ensure that your `_document.js` is importing and rendering all of the [required components](https://nextjs.org/docs#custom-document).
In this case you are most likely not rendering the `<Head>` component imported from `next/document`.
...@@ -47,6 +47,15 @@ export default class HeadManager { ...@@ -47,6 +47,15 @@ export default class HeadManager {
updateElements (type, components) { updateElements (type, components) {
const headEl = document.getElementsByTagName('head')[0] const headEl = document.getElementsByTagName('head')[0]
const headCountEl = headEl.querySelector('meta[name=next-head-count]') const headCountEl = headEl.querySelector('meta[name=next-head-count]')
if (process.env.NODE_ENV !== 'production') {
if (!headCountEl) {
console.error(
'Warning: next-head-count is missing. https://err.sh/next.js/next-head-count-missing'
)
return
}
}
const headCount = Number(headCountEl.content) const headCount = Number(headCountEl.content)
const oldTags = [] const oldTags = []
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment