Skip to content

Bug: Context provider updates forcing Suspense fallback on hydration #24476

@liuyenwei

Description

@liuyenwei

React version: 18.1.0

Steps To Reproduce

  1. Set up a ContextProvider and pass object as value (not-memoized)
  2. Wrap the ContextProvider around a Suspense boundary
  3. In a component, outside of the Suspense boundary, update the context value inside of a useEffect
  4. Notice that the de-hydrated suspense content rendered by the server now switches back to the fallback on the client

Link to code example:
https://codesandbox.io/s/react-18-redux-ssr-forked-rbkvtv?file=/src/App.js (forked from a redux ssr sandbox bc I originally thought this was a hydration issue with redux)

The current behavior

The update to the context provider causes the suspense boundary to switch to the fallback since it has not finished hydrating yet and shows this error:
image

The expected behavior

The suspense boundary is able to hydrate without switching to the fallback on the client.

Note

Updating the ContextProvider to memoize the value using useMemo addresses the issue but I am still curious if this is expected behavior or a bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: UnconfirmedA potential issue that we haven't yet confirmed as a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions