Fix some races due to promises completing after we've switched rooms
Add a few isMounted() checks to promise handlers so that we don't end up throwing NPEs.
This commit is contained in:
parent
8170288acb
commit
62cf34b58c
2 changed files with 18 additions and 5 deletions
|
@ -353,11 +353,14 @@ module.exports = React.createClass({
|
||||||
_paginateCompleted: function() {
|
_paginateCompleted: function() {
|
||||||
debuglog("paginate complete");
|
debuglog("paginate complete");
|
||||||
|
|
||||||
this.setState({
|
// we might have switched rooms since the paginate started - just bin
|
||||||
room: MatrixClientPeg.get().getRoom(this.props.roomId)
|
// the results if so.
|
||||||
});
|
if (!this.isMounted()) return;
|
||||||
|
|
||||||
this.setState({paginating: false});
|
this.setState({
|
||||||
|
room: MatrixClientPeg.get().getRoom(this.props.roomId),
|
||||||
|
paginating: false,
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
onSearchResultsFillRequest: function(backwards) {
|
onSearchResultsFillRequest: function(backwards) {
|
||||||
|
@ -535,7 +538,7 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
return searchPromise.then(function(results) {
|
return searchPromise.then(function(results) {
|
||||||
debuglog("search complete");
|
debuglog("search complete");
|
||||||
if (!self.state.searching || self.searchId != localSearchId) {
|
if (!this.isMounted() || !self.state.searching || self.searchId != localSearchId) {
|
||||||
console.error("Discarding stale search results");
|
console.error("Discarding stale search results");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -158,6 +158,10 @@ module.exports = React.createClass({
|
||||||
|
|
||||||
// check the scroll state and send out backfill requests if necessary.
|
// check the scroll state and send out backfill requests if necessary.
|
||||||
checkFillState: function() {
|
checkFillState: function() {
|
||||||
|
if (!this.isMounted()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
var sn = this._getScrollNode();
|
var sn = this._getScrollNode();
|
||||||
|
|
||||||
// if there is less than a screenful of messages above or below the
|
// if there is less than a screenful of messages above or below the
|
||||||
|
@ -346,6 +350,12 @@ module.exports = React.createClass({
|
||||||
* message panel.
|
* message panel.
|
||||||
*/
|
*/
|
||||||
_getScrollNode: function() {
|
_getScrollNode: function() {
|
||||||
|
if (!this.isMounted()) {
|
||||||
|
// this shouldn't happen, but when it does, turn the NPE into
|
||||||
|
// something more meaningful.
|
||||||
|
throw new Error("ScrollPanel._getScrollNode called when unmounted");
|
||||||
|
}
|
||||||
|
|
||||||
var panel = ReactDOM.findDOMNode(this.refs.geminiPanel);
|
var panel = ReactDOM.findDOMNode(this.refs.geminiPanel);
|
||||||
|
|
||||||
// If the gemini scrollbar is doing its thing, this will be a div within
|
// If the gemini scrollbar is doing its thing, this will be a div within
|
||||||
|
|
Loading…
Reference in a new issue