Skip to content
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

Add additional fix in hydration error document #40675

Merged
merged 5 commits into from Sep 23, 2022
Merged

Conversation

abdennor
Copy link
Contributor

@abdennor abdennor commented Sep 19, 2022

I had the same issue, so the fix that worked for me was pulled from this thread https://stackoverflow.com/a/71870995

I have been experiencing the same problem lately with NextJS and i am not sure if my observations are applicable to other libraries. I had been wrapping my components with an improper tag that is, NextJS is not comfortable having a p tag wrapping your divs, sections etc so it will yell "Hydration failed because the initial UI does not match what was rendered on the server". So I solved this problem by examining how my elements were wrapping each other. With material UI you would need to be cautious for example if you use a Typography component as a wrapper, the default value of the component prop is "p" so you will experience the error if you don't change the component value to something semantic. So in my own opinion based on my personal experience the problem is caused by improper arrangement of html elements and to solve the problem in the context of NextJS one will have to reevaluate how they are arranging their html element

Documentation / Examples

  • Make sure the linting passes by running pnpm lint
  • The "examples guidelines" are followed from our contributing doc

I had the same issue, so the fix that worked for me was pulled from this thread https://stackoverflow.com/a/71870995
errors/react-hydration-error.md Outdated Show resolved Hide resolved
@awareness481
Copy link
Contributor

Rather than this specific example, of div inside p, I would suggest that this needs to be worded something like Invalid HTML may cause a hydration mismatch
I don't think having the stackoverflow link is a great idea as the answer isn't correct enough.

@abdennor
Copy link
Contributor Author

@awareness481 yes, that would be more appropriate thank you

@thanhtutzaw
Copy link

Agree , I can't put div inside p

@ijjk ijjk changed the title another possible fix for hydration error Add additional fix in hydration error document Sep 23, 2022
Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ijjk ijjk merged commit 1bbd264 into vercel:canary Sep 23, 2022
@abdennor abdennor deleted the patch-1 branch September 28, 2022 12:51
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 29, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants