React 18: Updating state in an effect during mount causes hydration mismatch
See original GitHub issueWhat version of React, ReactDOM/React Native, Redux, and React Redux are you using?
- React: 18.0.0-alpha-88d121899-20210811
- ReactDOM: 18.0.0-alpha-88d121899-20210811
- Redux: 4.1.1
- React Redux: 7.2.4
What is the current behavior?
When updating the store in an effect outside of a Suspense boundary, hydration mismatches are reported for components reading from the store inside Suspense boundaries.
Warning: Prop `className` did not match. Server: "language-js" Client: "language-ts"
Components reading the store outside of Suspense boundaries issue no hydration mismatches.
<Store>
<Suspense fallback={null}>
<Demo>inside suspense has hydration mismatch</Demo>
</Suspense>
<Demo>outside suspense has no hydration mismatch</Demo>
<UpdatesStore />
</Store>
The codesandbox includes an implementation using React Context as well where no problem is reported.
What is the expected behavior?
No hydration mismatches.
Which browser and OS are affected by this issue?
Chrome 92, Ubuntu 20.04
Did this work in previous versions of React Redux?
- Yes
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:9 (9 by maintainers)
Top Results From Across the Web
Handling the React server hydration mismatch error
The real problem is that our UI is “stale.” React doesn't update the UI to match the props that were rendered differently by...
Read more >React v18.0 – React Blog
Batching is when React groups multiple state updates into a single re-render for better performance. Without automatic batching, we only batched ...
Read more >How to solve react hydration error in Nextjs - Stack Overflow
This is quite a common issue in Next.js and a lot of times it's caused by incorrect JSX wrapping patterns. Check this question,...
Read more >Avoiding hydration mismatch when using React hooks
One of the most difficult classes of bugs to track down and fix are those which appear seemingly at random. Bugs caused by...
Read more >React 18: A Guide to Its New Features and Updates
React simulates mounting the component with the previous state. Layout effects are created. Effects setup code runs. Planning to Upgrade Your ...
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
Is this something I should do? Because I already tried with just React Context without success. At this point I’d have to dig into how react-redux works.
SSR-related as shown in the codesandbox.
Given that I see no hydration warnings using React Context, I don’t believe this is a React bug. But if you can reproduce the same issue with just React, we can file it against the React repository.