From 7b405d0d9cc02e55c2a8e1f8448353499d5c27ac Mon Sep 17 00:00:00 2001 From: Richard van der Hoff Date: Mon, 18 Apr 2016 14:51:17 +0100 Subject: [PATCH] Don't setState after unmounting a component Fix a warning which happens if a LinkPreviewWidget is unmounted before the preview request completes. Also add missing .done to promise chain --- src/components/views/rooms/LinkPreviewWidget.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/components/views/rooms/LinkPreviewWidget.js b/src/components/views/rooms/LinkPreviewWidget.js index 302e0f1e75..ba438c1d12 100644 --- a/src/components/views/rooms/LinkPreviewWidget.js +++ b/src/components/views/rooms/LinkPreviewWidget.js @@ -45,14 +45,18 @@ module.exports = React.createClass({ }, componentWillMount: function() { + this.unmounted = false; MatrixClientPeg.get().getUrlPreview(this.props.link, this.props.mxEvent.getTs()).then((res)=>{ + if (this.unmounted) { + return; + } this.setState( { preview: res }, this.props.onWidgetLoad ); }, (error)=>{ console.error("Failed to get preview for " + this.props.link + " " + error); - }); + }).done(); }, componentDidMount: function() { @@ -65,6 +69,10 @@ module.exports = React.createClass({ linkifyElement(this.refs.description, linkifyMatrix.options); }, + componentWillUnmount: function() { + this.unmounted = true; + }, + onImageClick: function(ev) { var p = this.state.preview; if (ev.button != 0 || ev.metaKey) return;