Skip to content

Bug: Empty destroy function prevents "state update on an unmounted component" #24069

Closed
@fromflux

Description

@fromflux

Adding a useEffect with an empty clean up callback prevents async "state update after unmount" warning in certain cases.

React version: 17.0.2

Steps To Reproduce

  1. In the example provided
  2. Trigger the async request by clicking the Load button
  3. Navigate away before request resolves

Link to code example:

https://codesandbox.io/s/spring-frog-9n59kj?file=/src/LoaderPage.jsx

The current behavior

In React 17.0.2 adding a useEffect with empty clean up callback prevents the "state update on an unmounted component" warning

The expected behavior

In React 16, the warning is shown unless the clean up call back does work, for example by updating a guard "instance variable" in the vain of the "isMounted" scenario (as in https://stackoverflow.com/a/60907638).

I am not clear on what the current intention is, given #17925 and the fact that in 18.0.0-rc2 the state update is not performed after unmount in this example, with or without the empty destroy function.

Activity

cdscawd

cdscawd commented on Mar 11, 2022

@cdscawd

Fuck USA

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

        Participants

        @fromflux@cdscawd

        Issue actions

          Bug: Empty destroy function prevents "state update on an unmounted component" · Issue #24069 · facebook/react