Semantic-Org / Semantic-UI-React

The official Semantic-UI-React integration
https://react.semantic-ui.com
MIT License
13.21k stars 4.05k forks source link

Bug: Put contentRef in state to let EventStack track changes #4388

Open GuiCodron opened 1 year ago

GuiCodron commented 1 year ago

contentRef is passed to EventStack to subscribe for mouse events. Passing a contentRef created using React.createRef() does not allow EventStack to keep track of contentRef changes (since only contentRef.current changes). Ultimately when PortalInner unmount contentRef.current is set to undefined and EventStack unsubscribe handlers with undefined as a target instead of unsubscribing with real content. This leads to the event-stack Map keeping a reference to the real content thus leaking all dom tree related to the contentRef node.

Putting contentRef in the state and passing the element directly to EventStack allow for EventStack to detect change in its props and execute the componentDidUpdate routine which unsubscribe from the previous element on unmount.

welcome[bot] commented 1 year ago

💖 Thanks for opening this pull request! 💖

Here is a list of things that will help get it across the finish line:

We get a lot of pull requests on this repo, so please be patient and we will get back to you as soon as we can.