Merge pull request #3958 from vector-im/rav/roomdirectory_unmounting

Fix some setState-after-unmount in roomdirectory
This commit is contained in:
Richard van der Hoff 2017-05-18 19:06:18 +01:00 committed by GitHub
commit b886215fdd

View file

@ -60,6 +60,7 @@ module.exports = React.createClass({
}, },
componentWillMount: function() { componentWillMount: function() {
this._unmounted = false;
this.nextBatch = null; this.nextBatch = null;
this.filterTimeout = null; this.filterTimeout = null;
this.scrollPanel = null; this.scrollPanel = null;
@ -97,6 +98,10 @@ module.exports = React.createClass({
// sideOpacity: 1.0, // sideOpacity: 1.0,
// middleOpacity: 1.0, // middleOpacity: 1.0,
// }); // });
if (this.filterTimeout) {
clearTimeout(this.filterTimeout);
}
this._unmounted = true;
}, },
refreshRoomList: function() { refreshRoomList: function() {
@ -139,6 +144,11 @@ module.exports = React.createClass({
return; return;
} }
if (this._unmounted) {
// if we've been unmounted, we don't care either.
return;
}
this.nextBatch = data.next_batch; this.nextBatch = data.next_batch;
this.setState((s) => { this.setState((s) => {
s.publicRooms.push(...data.chunk); s.publicRooms.push(...data.chunk);
@ -156,6 +166,12 @@ module.exports = React.createClass({
// requests either // requests either
return; return;
} }
if (this._unmounted) {
// if we've been unmounted, we don't care either.
return;
}
this.setState({ loading: false }); this.setState({ loading: false });
console.error("Failed to get publicRooms: %s", JSON.stringify(err)); console.error("Failed to get publicRooms: %s", JSON.stringify(err));
var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog"); var ErrorDialog = sdk.getComponent("dialogs.ErrorDialog");