Skip to content

Commit 04cf779

Browse files
devknollTimer
authored andcommitted
Add warning for missing <Head> (vercel#8276)
* Add warning for missing <Head> * Update the warning to be eliminated away in production * Update head-manager.js
1 parent 3eca886 commit 04cf779

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

errors/next-head-count-missing.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# `next-head-count` is missing
2+
3+
#### Why This Error Occurred
4+
5+
You have a custom `pages/_document.js` that doesn't have the components required for Next.js to render correctly.
6+
7+
#### Possible Ways to Fix It
8+
9+
Ensure that your `_document.js` is importing and rendering all of the [required components](https://nextjs.org/docs#custom-document).
10+
11+
In this case you are most likely not rendering the `<Head>` component imported from `next/document`.

packages/next/client/head-manager.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export default class HeadManager {
4747
updateElements (type, components) {
4848
const headEl = document.getElementsByTagName('head')[0]
4949
const headCountEl = headEl.querySelector('meta[name=next-head-count]')
50+
if (process.env.NODE_ENV !== 'production') {
51+
if (!headCountEl) {
52+
console.error(
53+
'Warning: next-head-count is missing. https://err.sh/next.js/next-head-count-missing'
54+
)
55+
return
56+
}
57+
}
58+
5059
const headCount = Number(headCountEl.content)
5160
const oldTags = []
5261

0 commit comments

Comments
 (0)