Skip to content

Conversation

@avet-m
Copy link

@avet-m avet-m commented Jun 8, 2021

There are some cases when interaction manager's task executing when component have already unmounted and React return a warning when setState happed on unmounted component. The whole warning you can see below:

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

So this tiny fix will cancel task on component unmount.

Fix for this 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
Comment on lines +8 to +13
const {cancel} = InteractionManager.runAfterInteractions(() => {
updateInteractionStatus(true)
})

return () => {
cancel?.()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

runAfterInteractions returns a promise and I'm not sure if they are required to have their methods bound so that they work without this being set 🤔

Also, I think that cancel will always be set, right? It's documented as returning a cancelable promise 🤔

What do you think about this instead:

Suggested change
const {cancel} = InteractionManager.runAfterInteractions(() => {
updateInteractionStatus(true)
})
return () => {
cancel?.()
const promise = InteractionManager.runAfterInteractions(() => {
updateInteractionStatus(true)
})
return () => {
promise.cancel()
@pvinis
Copy link
Member

pvinis commented Feb 21, 2025

already fixed.

@pvinis pvinis closed this Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants