mirror of
https://github.com/element-hq/element-web
synced 2024-11-26 19:26:04 +03:00
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
This commit is contained in:
parent
8e1b0ee0a9
commit
7b405d0d9c
1 changed files with 9 additions and 1 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue