First-off, I do know I should not nest <p>
tags.
So I created a Next.js application and I have a component that sets rich text html as follows:
<Typography
dangerouslySetInnerHTML={{
__html: richText
}}
/>
The react component Typography
is just a p
tag in the end so this could simply be written as:
<p
dangerouslySetInnerHTML={{
__html: richText
}}
/>
So when the browser loads the page, my content does not show up and I am left with the console warning:
Warning: Prop 'dangerouslySetInnerHTML' did not match. Server: "" Client: "<p>...</p>"
After a lengthy debugging session, during cleaning up, using the <span>
instead of <p>
was the solution
<span
dangerouslySetInnerHTML={{
__html: richText
}}
/>
Nested p tags was a mistake, regardless, what is happening that makes Next.js not render this particular content resulting in the empty string Server: ""
? Is Next.js just simply very sensitive to errors and warnings?
I've had the same problem because in the richtext
I was getting <p>
tags too, so when I switched my wrapping tag from <p>
to <div>
that error disappeared.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With