Skip to content

Can't perform a React state update on an unmounted component. #40

Description

@MarkLyck

I'm running into an error with the FlagsmithProvider in short unit tests.

I get the following error originating from this library when testing even a simple component that doesn't use flasgsmith-react:

Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in a useEffect cleanup function.
    at FlagsmithProvider (/Users/m/colony/colony-frontend/node_modules/flagsmith-react/dist/flagsmith-react.cjs.js:1018:18)
    at /Users/m/colony/colony-frontend/src/test/TestProvider.tsx:90:17
    at Providers (/Users/m/colony/colony-frontend/src/test/TestProvider.tsx:42:3)
    at Wrapper

My <TestProvider /> component wraps any test render with a few Providers I need throughout my Application, FlagSmithProvider being one of them.

Currently my test passes and throws the above error.

If I artifically make my test "slower". by adding a wait function to the end of it with 1ms, my test passes with no errors.

My guess is that the FlagsmithProvider is running some initialization code or fetching data, that does not get cleaned up or cancelled properly if it is unmounted shortly after being mounted.

Any chance you can add some cleanup code to handle this scenario?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions