RoomView: guard against unmounting during peeking

it's possible for the user to change room before the peek operation completes. Check if we've been unmounted before setting state.
This commit is contained in:
Richard van der Hoff 2018-02-08 10:01:24 +00:00 committed by GitHub
parent d51f6ceea2
commit 5823b32ab1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -264,12 +264,19 @@ module.exports = React.createClass({
isPeeking: true, // this will change to false if peeking fails
});
MatrixClientPeg.get().peekInRoom(roomId).then((room) => {
if (this.unmounted) {
return;
}
this.setState({
room: room,
peekLoading: false,
});
this._onRoomLoaded(room);
}, (err) => {
if (this.unmounted) {
return;
}
// Stop peeking if anything went wrong
this.setState({
isPeeking: false,
@ -286,7 +293,7 @@ module.exports = React.createClass({
} else {
throw err;
}
}).done();
});
}
} else if (room) {
// Stop peeking because we have joined this room previously