From e91bb09c332476176eb07e86a2d911f3bf01b521 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Mon, 12 Feb 2018 22:20:53 +0200 Subject: [PATCH] #389: fix react warning about setState on unmounted component --- src/components/auth/PanelTransition.js | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/components/auth/PanelTransition.js b/src/components/auth/PanelTransition.js index edc67f3..8497003 100644 --- a/src/components/auth/PanelTransition.js +++ b/src/components/auth/PanelTransition.js @@ -109,6 +109,8 @@ class PanelTransition extends Component { panelId: this.props.Body && this.props.Body.type.panelId }; + timerIds = []; // this is a list of a probably running timeouts to clean on unmount + getChildContext() { return { auth: this.props.auth, @@ -121,7 +123,9 @@ class PanelTransition extends Component { this.setState({isHeightDirty: false}); // wait till transition end - setTimeout(resolve, 200); + this.timerIds.push( + setTimeout(resolve, 200) + ); } ) ), @@ -148,13 +152,20 @@ class PanelTransition extends Component { }); if (forceHeight) { - setTimeout(() => { - this.setState({forceHeight: 0}); - }, 100); + this.timerIds.push( + setTimeout(() => { + this.setState({forceHeight: 0}); + }, 100) + ); } } } + componentWillUnmount() { + this.timerIds.forEach((id) => clearTimeout(id)); + this.timerIds = []; + } + render() { const {contextHeight, forceHeight} = this.state;