Skip to content

Bug: useSyncExternalStore will cause hydration missmatch in StrictMode if serverSnapshot is different from snapshot #26095

@promer94

Description

@promer94

React version

React version: 18.3.0-next-b0671f9ea-20230130

Problem

In StrictMode, when using hydrateRoot to render a component that using useSyncExternalStore 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions