sekoyo / react-image-crop

A responsive image cropping tool for React
ISC License
3.77k stars 339 forks source link

Memory leak risk due to event listeners not removed on componentWillUnmount #580

Closed rockinghelvetica closed 4 months ago

rockinghelvetica commented 4 months ago

https://github.com/sekoyo/react-image-crop/blob/0a19cbad4fbf988cb178e00f15823d96e634992d/src/ReactCrop.tsx#L172-L176

I'm investigating an interaction glitch with the crop tool, and tangentially noticed that componentWillUnmount assumes it won't occur in the middle of the crop interaction. I imagine this is true in most applications, but it feels safer to ensure the events get torn down. Thoughts?

componentWillUnmount() {
    if (this.resizeObserver) {
        this.resizeObserver.disconnect()
    }
    // Ensure all event listeners are removed
    this.unbindDocMove()
}
sekoyo commented 4 months ago

Yep makes sense thanks, pushed to master so will go up in next release