From 86055bc476ae46139bbe386b993aa8c8962e5899 Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Thu, 18 May 2017 13:41:54 +0100 Subject: [PATCH] Fix some setState-after-unmount in roomdirectory Give the RoomDirectory and unmounted guard, and use it to avoid some setState warnings. Also, cancel the filterTimeout (no point in leaving it around). There are still plenty of other opportunities to setState after unmount, but the filterTimeout was causing noise in the test. --- src/components/structures/RoomDirectory.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/components/structures/RoomDirectory.js b/src/components/structures/RoomDirectory.js index 91046959..523ee56e 100644 --- a/src/components/structures/RoomDirectory.js +++ b/src/components/structures/RoomDirectory.js @@ -60,6 +60,7 @@ module.exports = React.createClass({ }, componentWillMount: function() { + this._unmounted = false; this.nextBatch = null; this.filterTimeout = null; this.scrollPanel = null; @@ -97,6 +98,10 @@ module.exports = React.createClass({ // sideOpacity: 1.0, // middleOpacity: 1.0, // }); + if (this.filterTimeout) { + clearTimeout(this.filterTimeout); + } + this._unmounted = true; }, refreshRoomList: function() { @@ -139,6 +144,11 @@ module.exports = React.createClass({ return; } + if (this._unmounted) { + // if we've been unmounted, we don't care either. + return; + } + this.nextBatch = data.next_batch; this.setState((s) => { s.publicRooms.push(...data.chunk); @@ -156,6 +166,12 @@ module.exports = React.createClass({ // requests either return; } + + if (this._unmounted) { + // if we've been unmounted, we don't care either. + return; + } + this.setState({ loading: false }); console.error("Failed to get publicRooms: %s", JSON.stringify(err)); var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");