negomi / react-burger-menu

:hamburger: An off-canvas sidebar component with a collection of effects and styles using CSS transitions and SVG path animations
http://negomi.github.io/react-burger-menu/
MIT License
5.05k stars 586 forks source link

MenuFactory not clearing timeout when component unmounts #385

Closed dawnmist closed 4 years ago

dawnmist commented 4 years ago

The menuFactory sets up a timer function to be run when the menu visibility is toggled here: https://github.com/negomi/react-burger-menu/blob/3487781faf0b9bf7b8664e2e5fe59b3a341c9380/src/menuFactory.js#L52-L58

In our situation, the burger menu component only exists after the user has logged into the site. One of the options in the menu is the Logout option.

When the user selects Logout, the timer gets created (because the menu is changing from visible to invisible again) and then the component gets unmounted entirely. When the timeout function then fires it tries to invoke code on a component that no longer exists to modify settings on the pageWrapId and outerWrapId divs that also no longer exist.

The componentWillUnmount function needs to have the same code in https://github.com/negomi/react-burger-menu/blob/3487781faf0b9bf7b8664e2e5fe59b3a341c9380/src/menuFactory.js#L52 added to this function, so that if the menu component is unmounted as a result of activating an item in the menu it cancels the timer function properly.

negomi commented 4 years ago

Hi @dawnmist, I've just fixed this and released the change in 2.6.16.

Thanks for the detailed bug report! 🙂