mirror of https://github.com/vector-im/riot-web
Merge pull request #276 from matrix-org/rav/issue_1398
Don't setState after unmounting a componentpull/21833/head
commit
4661270ff2
|
@ -45,14 +45,18 @@ module.exports = React.createClass({
|
||||||
},
|
},
|
||||||
|
|
||||||
componentWillMount: function() {
|
componentWillMount: function() {
|
||||||
|
this.unmounted = false;
|
||||||
MatrixClientPeg.get().getUrlPreview(this.props.link, this.props.mxEvent.getTs()).then((res)=>{
|
MatrixClientPeg.get().getUrlPreview(this.props.link, this.props.mxEvent.getTs()).then((res)=>{
|
||||||
|
if (this.unmounted) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
this.setState(
|
this.setState(
|
||||||
{ preview: res },
|
{ preview: res },
|
||||||
this.props.onWidgetLoad
|
this.props.onWidgetLoad
|
||||||
);
|
);
|
||||||
}, (error)=>{
|
}, (error)=>{
|
||||||
console.error("Failed to get preview for " + this.props.link + " " + error);
|
console.error("Failed to get preview for " + this.props.link + " " + error);
|
||||||
});
|
}).done();
|
||||||
},
|
},
|
||||||
|
|
||||||
componentDidMount: function() {
|
componentDidMount: function() {
|
||||||
|
@ -65,6 +69,10 @@ module.exports = React.createClass({
|
||||||
linkifyElement(this.refs.description, linkifyMatrix.options);
|
linkifyElement(this.refs.description, linkifyMatrix.options);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
componentWillUnmount: function() {
|
||||||
|
this.unmounted = true;
|
||||||
|
},
|
||||||
|
|
||||||
onImageClick: function(ev) {
|
onImageClick: function(ev) {
|
||||||
var p = this.state.preview;
|
var p = this.state.preview;
|
||||||
if (ev.button != 0 || ev.metaKey) return;
|
if (ev.button != 0 || ev.metaKey) return;
|
||||||
|
|
Loading…
Reference in New Issue