Next.JS / React 18 - Hydration Error
See original GitHub issueCurrent Behavior
Unless react-player
is loaded on the client-side using dynamic/no-ssr or useEffect, React will panic with a hydration error.
Expected Behavior
Use of SSR should not result in a hydration error.
Steps to Reproduce
- Using Next.JS, import
react-player
and follow typical implementation instructions. - Error
Other Information
There is a great thread on Stack Overflow here (https://stackoverflow.com/questions/71706064/react-18-hydration-failed-because-the-initial-ui-does-not-match-what-was-render) where devs list various solutions to related issues.
Examples:
react
andreact-dom
may need to be updated.- Wrapping tags improperly, such as
<div>
inside<p>
will cause the error. - Lazy modules need to be wrapped in
<Suspense>
.
Please check again these scenarios in the codebase. Thank you!
Issue Analytics
- State:
- Created a year ago
- Reactions:13
- Comments:14 (1 by maintainers)
Top Results From Across the Web
react-hydration-error - Next.js
In general this issue is caused by using a specific library or application code that is relying on something that could differ between...
Read more >React 18: Hydration failed because the initial UI does not ...
I have been experiencing the same problem lately with NextJS and i am not sure if my observations are applicable to other libraries....
Read more >Hydration failed because the initial UI does not match ... - GitHub
It's likely that you have a mismatch between the server output and the client. Before React 18, you'd only get an error in...
Read more >How To Solve Hydration Error In Next.js | by Westin Tang
The reason for the error has been clearly stated in the error message: the hydration failed due to the inconsistency between the UI...
Read more >Fix Next.js “Text content does not match server-rendered ...
Learn how to fix the React hydration error “Text content does not match server-rendered HTML” so you can personalize & transform HTML in ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I agree that ReactPlayer should be SSR-friendly out of the box, @cookpete what do you think?
For now, until that happens, another workaround is to lazy-load the player using Next.js dynamic imports, as mentioned by @inderrr in this comment:
Have you tried this?
It’s basically checking the window.