-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
Bug: useSyncExternalStore will cause hydration missmatch in StrictMode
if serverSnapshot
is different from snapshot
#26095
Comments
serverSnapshot
is different from serverSnapshot
is different from snapshot
serverSnapshot
is different from snapshot
StrictMode
if serverSnapshot
is different from snapshot
Can confirm. I reduced the repros a bit more so that it's easier to comprehend what's going on: 18.3.0-next-2ac77aab9-20221029 (with StrictMode) broken: https://codesandbox.io/s/useses-18-3-forked-co9ix3 Broke somewhere in cf3932b...2ac77aa |
Previously, we'd call and use getSnapshot on the second render resulting in `Warning: Text content did not match. Server: "Nay!" Client: "Yay!"` and then `Error: Text content does not match server-rendered HTML.`. Fixes facebook#26095. Closes facebook#26113.
Previously, we'd call and use getSnapshot on the second render resulting in `Warning: Text content did not match. Server: "Nay!" Client: "Yay!"` and then `Error: Text content does not match server-rendered HTML.`. Fixes #26095. Closes #26113. Closes #25650. --------- Co-authored-by: eps1lon <[email protected]>
Previously, we'd call and use getSnapshot on the second render resulting in `Warning: Text content did not match. Server: "Nay!" Client: "Yay!"` and then `Error: Text content does not match server-rendered HTML.`. Fixes #26095. Closes #26113. Closes #25650. --------- Co-authored-by: eps1lon <[email protected]> DiffTrain build for [4cd7065](4cd7065)
Previously, we'd call and use getSnapshot on the second render resulting in `Warning: Text content did not match. Server: "Nay!" Client: "Yay!"` and then `Error: Text content does not match server-rendered HTML.`. Fixes facebook#26095. Closes facebook#26113. Closes facebook#25650. --------- Co-authored-by: eps1lon <[email protected]>
Previously, we'd call and use getSnapshot on the second render resulting in `Warning: Text content did not match. Server: "Nay!" Client: "Yay!"` and then `Error: Text content does not match server-rendered HTML.`. Fixes #26095. Closes #26113. Closes #25650. --------- Co-authored-by: eps1lon <[email protected]> DiffTrain build for commit 4cd7065.
React version
React version: 18.3.0-next-b0671f9ea-20230130
Problem
In
StrictMode
, when using hydrateRoot to render a component that usinguseSyncExternalStore
it seems that useSES will do hydration twice.But in second hydration process, useSES does not use the result of
getServerSnapshot
as initial state, which will cause hydration error.This problem will only happen in
development
mode,Reproduce
Link to code example:
https://codesandbox.io/s/useses-18-3-rojznv
It works well in react 18.2
https://codesandbox.io/s/useses-18-2-13iskc
The text was updated successfully, but these errors were encountered: