-
Notifications
You must be signed in to change notification settings - Fork 27k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Using <title> in _document.js's <Head> tag should show a warning to use _app.js instead #4596
Comments
Question on this issue - is including Can I also ask what's the thinking behind |
A title is directly correlated to a page. So it should be set in a page. |
Hi @timneutkens, I could take this one |
@davscro go ahead 👍🙌 |
Ok, thanks. |
Hi :) I've added isTitleExists () {
if (this.props.children.filter(children => children.type != "title").length > 0) {
return;
}
console.log("Warning: the <title> should be used only in _app.js and other pages. https://err.sh/next.js/url-deprecated")
} Any hints? p.s. sorry, @davscro I was bored 😃 looking forward for your solution 👍 |
Hi @teleginzhenya, you are on the right direction but children could be an object too so your code will break. Also be careful with equality comparisons, I would suggest you to always use strict comparison 😉 |
https://github.com/zeit/next.js/tree/canary/examples/with-styled-components This example should be fixed? it use |
Yes, feel free to update it @rainstormza. I'm going to close this issue as it was fixed in #5160. |
@timneutkens |
You can use the head tag, just not for setting <title> as it leads to unexpected behavior |
Using react helmet seems to trigger this warning. |
What if I purposely want this behavior? How can I stop it from saying...
|
import Head from 'next/head'; from your pages e.g. index.js etc. <title> cool title </title> |
Hi There, I followed the error message, landing up here, moved my Head element, title and description meta tag to _app and received the following:
|
See #9647 (comment) |
so then, if I'm understanding right, the current best practice to insert |
@crevulus Afaik, you can set a "global" title in |
Title metadata should be set at a page level. See https://nextjs.org/docs/api-reference/next/head and vercel/next.js#4596
You should import Head from |
Hey, I'm having some problems related to this issue. When creating a _document file, it prompts the following message:
For some reason, it prompts another warning saying.
And obviously, I can't set the title in the _document. Is someone having the same problem? Didn't think it was enough to create a new issue. |
Hey did anyone manage to solve this with Next 12? Using 12.0.6 currently. I have a _document.js but not specifying title/head in there. Using next/head in my pages and all of the tags land in the body not in head. It's a pretty bad result for SEO. |
If you have issues, I suggest opening a new bug report with a reproduction. 🙏 |
Bug report
Based on #3527
Describe the bug
Currently, users might add
<title>
in_document.js
which will lead to unexpected results withnext/head
since_document.js
is only rendered on the initial pre-render._app.js
is rendered on the server and client side, and is rendered as a normal React tree, whereas _document.js is rendered as static HTML.To Reproduce
Steps to reproduce the behavior, please provide code snippets or a repository:
_document.js
and add<title>
:Expected behavior
Above example should show a warning that
<title>
should only be used in _app.js and other pages. This can be done usingerr.sh
, create a link like:https://err.sh/next.js/no-document-title
and create a file in theerrors
directory:errors/no-document-title.md
The text was updated successfully, but these errors were encountered: