Cleanup timeout before unmount.

This commit is contained in:
Richard Lewis 2018-03-09 21:12:56 +00:00
parent a33859326e
commit 7e062090de
2 changed files with 15 additions and 1 deletions

View file

@ -204,6 +204,12 @@ export default class extends React.Component {
this.unmounted = true; this.unmounted = true;
dis.unregister(this.dispatcherRef); dis.unregister(this.dispatcherRef);
this.context.matrixClient.removeListener('sync', this.onClientSync); this.context.matrixClient.removeListener('sync', this.onClientSync);
this._afterComponentWillUnmount();
}
// To be overridden by subclasses (e.g. MStickerBody) for further
// cleanup after componentWillUnmount
_afterComponentWillUnmount() {
} }
onAction(payload) { onAction(payload) {

View file

@ -43,12 +43,13 @@ export default class MStickerBody extends MImageBody {
this.setState({ this.setState({
placeholderClasses: 'mx_MStickerBody_placeholder_invisible', placeholderClasses: 'mx_MStickerBody_placeholder_invisible',
}); });
setTimeout(() => { const hidePlaceholderTimer = setTimeout(() => {
this.setState({ this.setState({
placeholderVisible: false, placeholderVisible: false,
thumbnailClasses: 'mx_MStickerBody_thumbnail_visible', thumbnailClasses: 'mx_MStickerBody_thumbnail_visible',
}); });
}, 500); }, 500);
this.setState({hidePlaceholderTimer});
} }
_afterComponentDidMount() { _afterComponentDidMount() {
@ -69,6 +70,13 @@ export default class MStickerBody extends MImageBody {
} }
} }
_afterComponentWillUnmount() {
if (this.state.hidePlaceholderTimer) {
clearTimeout(this.state.hidePlaceholderTimer);
this.setState({hidePlaceholderTimer: null});
}
}
_messageContent(contentUrl, thumbUrl, content) { _messageContent(contentUrl, thumbUrl, content) {
let tooltip; let tooltip;
const tooltipBody = ( const tooltipBody = (