Skip to content

Bug: error in effect cleanup function no longer catchable #20946

@eps1lon

Description

@eps1lon

React version: 17.0.1
TL;DR: Fixed with skipUnmountedBoundaries = true

Steps To Reproduce

  1. Throw in an effect cleanup
  2. Try to catch it when wrapped in act()

Link to code example:
React 16
React 17

I also tested it locally and jest and couldn't catch the error as well.

The current behavior

The error is uncatchable and does not include the component stack ("The above error occurred").

The expected behavior

The error is catchable and does include the component stack i.e. React 16 behavior.

Context

I understand that the cleanup is now async but it's still flushed in act() so I would expect that an error thrown is catchable.

Originally reported in testing-library/react-testing-library#874

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