Skip to content

Bug: ErrorBoundary remounts children when errors are caught #26259

@fatton139

Description

@fatton139

In the render block of a ErrorBoundary component the props.children is remounted when getDerivedStateFromError derives a new state (or componentDidCatch sets a state).

Is this a special case ? Setting the state in any other manner (e.g componentDidUpdate doesn't have this behavior). I don't see this behavior documented in the React docs.

Thanks!

React version: 18.2.0 (Happens on 17.0.2 as well).

Steps To Reproduce

  1. In the code example increment the counter past 5 and the child component unmounts and mounts, the child state also resets

Link to code example: https://codesandbox.io/s/nifty-platform-wub9wn?file=/src/App.tsx

The current behavior

props.children unmounts and mounts.

The expected behavior

props.children rerenders.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions