This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
next/head
should prioritize document/head
over default tags
#30745
Labels
bug
Issue was opened via the bug report template.
What version of Next.js are you using?
12.0.2-canary.14
What version of Node.js are you using?
14.8.1
What browser are you using?
Firefox 93.0 (64-bit)
What operating system are you using?
macOS 11.6 (20G165)
How are you deploying your application?
next dev
Describe the Bug
When I add a
<meta name="viewport" content="viewport-fit=cover" />
tag to a custom_document.js
(because I don't intend for thatviewport
value to ever change in my app),next/head
still adds the default<meta name="viewport" content="width=device-width">
to my HTML and sends a warning to the console linking to an error message, which reads "Adding<meta name="viewport" ...>
inpages/_document.js
will lead to unexpected results since it cannot be deduped."But that isn't true. Next.js could deduplicate these viewport
meta
tags, ifnext/head
consulted a list ofdocument/head
children in its filtering process. All it rightly can't do is remove children fromdocument/head
, since_document.js
is only rendered once, in the server. But nothing needs to be removed fromdocument/head
in this case—the tag that's causing the problem and needs to be removed is the defaultmeta
tag innext/head
.Expected Behavior
Next.js should pass a read-only list of
document/head
children tonext/head
's filter, andnext/head
should letdocument/head
win all conflicts. And Next.js should then only warn users when they create<head>
tag conflicts themselves. The process would look like this:document/head
adds any elements defined within it to the initial HTML, without concerning itself about defaults or anything. No warnings necessary.document/head
added gets passed tonext/head
's filter somehow.next/head
filters out all elements that conflict withdocument/head
children.defaultHead
, that's good.next/head
child, then generate a warning, because the user goofed by defining conflicting tags in multiple places themselves.next/head
injects the results into the page.According to @lfades's definitions of
_document.js
and_app.js
in #13408 (comment),_document.js
is a better place for a static viewportmeta
tag than_app.js
because it's "something that you know only needs to be added once and has to be always there". There's no reason to keep injecting it over and over withnext/head
if the developer knows what they want. The only situation that should generate a warning is if the developer put their own viewportmeta
tags in bothdocument/head
and innext/head
, because then they've actually created a conflict.This would make the purposes of
document/head
andnext/head
much clearer, turning it intodocument/head
is for things that should never ever ever change throughout your entire app.next/head
is for things that you might want to change sometimes.This is in contrast to the current
document/head
policy, which is essentially "document/head
is for things that should never ever ever change except for the things that could conflict withnext/head
if you do something wrong." See #9794, #13230, #13408, #26534, #27142, and #30068 for more expressions of confusion over the currentdocument/head
policy.To Reproduce
Create a custom
Document
with a viewportmeta
tag like this:Or clone https://github.com/TyMick/nextjs-document-meta-tag. Then run
yarn dev
, watch your terminal for the console warning, and use your browser's HTML inspector to see the conflicting viewportmeta
tags.The text was updated successfully, but these errors were encountered: