add unmounted guard

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
pull/21833/head
Michael Telatynski 2018-02-10 16:01:19 +00:00
parent 25bc9cfbe7
commit 7bf05b0715
No known key found for this signature in database
GPG Key ID: 3F879DA5AD802A5E
1 changed files with 11 additions and 0 deletions

View File

@ -51,6 +51,8 @@ export default class Reply extends React.Component {
};
this.onQuoteClick = this.onQuoteClick.bind(this);
this.unmounted = false;
}
componentWillMount() {
@ -58,11 +60,17 @@ export default class Reply extends React.Component {
this.initialize();
}
componentWillUnmount() {
this.unmounted = true;
}
async initialize() {
const {parentEv} = this.props;
const inReplyTo = Reply.getInReplyTo(parentEv);
const ev = await this.getEvent(this.room, inReplyTo['event_id']);
if (this.unmounted) return;
if (ev) {
this.setState({
events: [ev],
@ -78,6 +86,7 @@ export default class Reply extends React.Component {
const inReplyTo = Reply.getInReplyTo(ev);
if (!inReplyTo) {
if (this.unmounted) return;
this.setState({
loading: false,
});
@ -85,6 +94,8 @@ export default class Reply extends React.Component {
}
const loadedEv = await this.getEvent(this.room, inReplyTo['event_id']);
if (this.unmounted) return;
if (loadedEv) {
this.setState({loadedEv});
} else {