tleunen / react-mdl

React Components for Material Design Lite
https://tleunen.github.io/react-mdl/
MIT License
1.76k stars 255 forks source link

Unmounting a Menu from the DOM throws an error #426

Closed DirtyHairy closed 7 years ago

DirtyHairy commented 7 years ago

Check out the testcase on codepen. The pen initially displays a Button ("nuke"), an IconButton and an attached Menu. Clicking the button removes the Button and just displays icon button and menu, causing react to unmount the menu at child position 3 and remount it at child position 2. On clicking the button, the debugger shows that an exception is thrown in the process.

The reason for this bug is that MDL does not clean the DOM when the element is downgraded, leaving react with the wrapper container as the direct child of the surrounding div (instead of the original ul). React then tries to unmount the ul from its supposed parent (the div), causing the exception to be thrown. A possible solution is to perform the cleanup in componentWillUnmount after downgrading. I can prepare a corresponing pull request.