Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory leak bug because of unmounted Loading button #228

Closed
gweiying opened this issue Nov 13, 2020 · 1 comment · Fixed by #242
Closed

Memory leak bug because of unmounted Loading button #228

gweiying opened this issue Nov 13, 2020 · 1 comment · Fixed by #242
Assignees
Labels
P1 Do it now.

Comments

@gweiying
Copy link
Contributor

gweiying commented Nov 13, 2020

Because our modals unmount before the Loading button completes its state update, we receive the memory leak error message shown below:

Screenshot 2020-11-13 at 10 25 10 AM

This happens for all modals (mediaModal, hyperlinkModal etc) that close once the Loading button is clicked because of the following lines in the LoadingButton.jsx component link:

      onClick={async () => {
        setButtonLoading(true);
        await callback();
        setButtonLoading(false);
      }}
@kwajiehao kwajiehao added the P1 Do it now. label Nov 18, 2020
@kwajiehao kwajiehao self-assigned this Nov 18, 2020
@kwajiehao kwajiehao linked a pull request Nov 18, 2020 that will close this issue
@kwajiehao
Copy link
Contributor

So it turns out that the issue isn't to do with the lines specified:

      onClick={async () => {
        setButtonLoading(true);
        await callback();
        setButtonLoading(false);
      }}

but from the fact that we are attempting to set the button loading state to false even after the LoadingButton component has unmounted (because the modal has closed). The fix is to add a condition to update state only when the component is mounted (reference: https://stackoverflow.com/questions/53949393/cant-perform-a-react-state-update-on-an-unmounted-component)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 Do it now.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants