- Notifications
You must be signed in to change notification settings - Fork29.8k
<title> problem: A title element received an array with more than 1 element as children#38256
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
On my website, users can type a search query into a search field. I would like to set the My first question is:Does it make a difference (SEO-wise) if I set this title from a value returned from The other approach would look like this: And the second part of the question:No matter which approach I use, I'm getting this warning in the console: which I didn't find any results in Google for whatsoever. |
BetaWas this translation helpful?Give feedback.
All reactions
Hi,
The warning is because when you do:
constHome:NextPage=()=>{constworld="World";return(<div><span>Hello{world} foo</span></div>);};
React renders:
<div><span>Hello<!-- -->World<!-- --> foo</span></div>
That's adiv with aspan child, with 0 children elements, but 5 nodes as children. There's a subtle difference between elements and nodes. Here's a handyvideo.
The 5 nodes are,text,comment,text,comment,text. The same is happening to yourtitle element.
Do this instead:
constHome:NextPage=()=>{constworld="World";constmessage=`Hello${world} foo`;return(<div><span>{message}</span></div>);};
Which outputs:
Replies: 9 comments 21 replies
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Hi, The warning is because when you do: constHome:NextPage=()=>{constworld="World";return(<div><span>Hello{world} foo</span></div>);}; React renders: <div><span>Hello<!-- -->World<!-- --> foo</span></div> That's a The 5 nodes are, Do this instead: constHome:NextPage=()=>{constworld="World";constmessage=`Hello${world} foo`;return(<div><span>{message}</span></div>);}; Which outputs: <div><span>Hello World foo</span></div> Now the SEO MeritsWell... in either case the bot/crawler, or whatever SEO entity, has to be arrive with the query in the URL already. Since you are using If you visit the site, with query in the URL, and then right click to "View Page Source", do you see the correct title there? If so, then you are good. EditThis answer has gotten a lot of feedback! I've also answered to it in a few other places but I think this one is a good complement: The key take-away from it:
For example in acodesandbox: import"./styles.css";import{renderToString}from"react-dom/server";constFooter=()=>{return(<footer><p>{`Copyright ©${newDate().getFullYear()} Sample Company`}</p></footer>);};// const Footer = () => {// return (// <footer>// <p>Copyright © {new Date().getFullYear()} Sample Company</p>// </footer>// );// };functionApp(){return(<><divclassName="App"><h1>Hello CodeSandbox</h1><h2>Start editing to see some magic happen!</h2></div><Footer/></>);}console.log(renderToString(<App/>));// log to the console to see what `renderToString` outputs |
BetaWas this translation helpful?Give feedback.
All reactions
👍 153😄 11🎉 19❤️ 29🚀 34
-
Thank you! Help me that solved it |
BetaWas this translation helpful?Give feedback.
All reactions
👍 4🎉 3
-
Thanks for the explanation . worked 100% . |
BetaWas this translation helpful?Give feedback.
All reactions
-
yes that's a good approach |
BetaWas this translation helpful?Give feedback.
All reactions
-
Very clear! so helpful |
BetaWas this translation helpful?Give feedback.
All reactions
-
Real clear, thank you kindly |
BetaWas this translation helpful?Give feedback.
All reactions
-
I tried the answer here and I seem to still have the error: I did not have such an error till after I upgraded to Next.JS v |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
This is another way to trigger this issue: <Head><title>{"hello"}</title></Head> Notice the blank space after |
BetaWas this translation helpful?Give feedback.
All reactions
🎉 15
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Ok I just checked my head and Yes it had the issue you described here I removed the extra space after the |
BetaWas this translation helpful?Give feedback.
All reactions
🎉 14
-
Perfect@lance1997 |
BetaWas this translation helpful?Give feedback.
All reactions
-
I have this issue remaining even after I delete every and <title> in my app.... The error message generated does not help me find a line number. |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Can you paste the code rendering your title? |
BetaWas this translation helpful?Give feedback.
All reactions
-
This solved for me - |
BetaWas this translation helpful?Give feedback.
All reactions
❤️ 5
-
} |
BetaWas this translation helpful?Give feedback.
All reactions
-
I just happened to find this warning in my console. Is there a lint rule or some other way to catch this? |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
thank you@icyJoseph withthis, it was the spaces in the
Before <title>{title}</title>// ↑ ↑// the whitespace is interpreted as 2 more text nodes After (fixed) <title>{title}</title> |
BetaWas this translation helpful?Give feedback.
All reactions
👍 2
-
Why not just doing it like this: |
BetaWas this translation helpful?Give feedback.
All reactions
😄 1
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
Yeah, I thought I had included it. I have answered this question a few times hehe, I'll copy paste from my other answers when I get home. |
BetaWas this translation helpful?Give feedback.
All reactions
-
What we are all doing is workaround, it should just accept This is clearly a bug |
BetaWas this translation helpful?Give feedback.
All reactions
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
-
I had the same Warning message and Solved : In my case, I had a Seo component and used the Head inside and had the title as a prop and had some text together like this : Due to the warning message, I had changed my Seo component using template literal(``) like below and error is gone: |
BetaWas this translation helpful?Give feedback.
All reactions
-
Yup, I had the exact same issue and concatenated them together before outputting to the |
BetaWas this translation helpful?Give feedback.