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

avoid set state on resize after component unmount #69

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

taras42
Copy link

@taras42 taras42 commented Dec 7, 2023

Hey, I found an issue that happens when component unmounts on resize. The resize event triggers first which calls to the debounced callback (action method in the component). Because the callback is debounced, it doesn't immediately invoke the action method, it unmounts the component first and only then it calls the action method that uses setState on an unmounted component which leads to this error:

"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 %s.%s", "the componentWillUnmount method", "
        in ClampLines"

The easiest solution I came up with is to just ignore the call because the component is unmounted anyway. There's a simple test for it too.

I do not contribute often, so I'm not sure what is the standard process (should I create an issue first?, etc..). Let me know if I need to do anything or if you have some other solution in mind so I can refactor.

(For me this issue happens when I go from desktop -> mobile break point and vise versa, there are some changes in the design and some components that use this lib get unmounted on resize)

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

Successfully merging this pull request may close these issues.

1 participant