react-container-dimensions icon indicating copy to clipboard operation
react-container-dimensions copied to clipboard

The handler `onResize` was still triggered after a component has been unmount

Open xile611 opened this issue 8 years ago • 9 comments

@okonet I find that when a ContainerDimensions element has been mount and unmount quickly an error is thrown. image

This error happens because the ready event of scroll is trigger although the listener has been removed. 2016-08-18 8 31 55

Do you have any idea to fix this problem ? Thank you !

xile611 avatar Aug 18 '16 13:08 xile611

Well, that's a warning, not an error, to begin with. I'm not sure how to solve this but I'm also not sure if this should be solved. Nothing bad is happening in this case. I could try set some flag that event listener is set and remove it on onUnmount. Do you want to submit a PR?

okonet avatar Aug 18 '16 15:08 okonet

@okonet Something don't show because this warning! That's why I notice this warning. I think some events are still triggered although the listener has been removed.

    componentWillUnmount() {
        this.elementResizeDetector.removeListener(this.parentNode, this.onResize)
    }

So I try to uninstall the resize detector, but some other error happens:

image

I'm not familiar with the element-resize-detector. It'll take me some time to find the solution. So I ask you for help!

xile611 avatar Aug 19 '16 03:08 xile611

Can you create a repo with this error easily reproducible?

okonet avatar Aug 19 '16 06:08 okonet

@okonet

https://github.com/xile611/react-container-dimensions-demo

And you are right! The warning doesn't affect the running of my component. It's another problem! But I want to fix this warning because I'm worried about whether this will result in performance problems.

xile611 avatar Aug 19 '16 13:08 xile611

👌 Submit a PR and don't forget tests!

okonet avatar Aug 19 '16 14:08 okonet

image

just need add the _isMounted to validate......I already test .....wish to handle

tomsue avatar Sep 30 '16 08:09 tomsue

wish fix as soon as.....Recharts use this package and get some effect .

tomsue avatar Sep 30 '16 08:09 tomsue

@tomsue Can you submit a PR. Please also add tests for it. Thanks!

okonet avatar Sep 30 '16 12:09 okonet

@tomsue It's a good idea to add the variable isMounted. Maybe you can submit a PR to fix this.

xile611 avatar Oct 11 '16 14:10 xile611