Cancel ScratchImage load if unmounted
This commit is contained in:
1 parent
5f6b89ec2a
commit
28cd140d9f
1 file changed
+11
-4
@@ -39,10 +39,13 @@ class ScratchImage extends React.PureComponent {
|
||||
storage
|
||||
.load(imageSource.assetType, imageSource.assetId)
|
||||
.then(asset => {
|
||||
const dataURI = asset.encodeDataURI();
|
||||
nextImage.setState({
|
||||
imageURI: dataURI
|
||||
});
|
||||
if (!nextImage.wasUnmounted) {
|
||||
const dataURI = asset.encodeDataURI();
|
||||
|
||||
nextImage.setState({
|
||||
imageURI: dataURI
|
||||
});
|
||||
}
|
||||
--this._currentJobs;
|
||||
this.loadPendingImages();
|
||||
});
|
||||
@@ -58,6 +61,10 @@ class ScratchImage extends React.PureComponent {
|
||||
const newState = this._loadImageSource(nextProps.imageSource);
|
||||
this.setState(newState);
|
||||
}
|
||||
componentWillUnmount () {
|
||||
this.wasUnmounted = true;
|
||||
ScratchImage._pendingImages.delete(this);
|
||||
}
|
||||
/**
|
||||
* Calculate the state changes necessary to load the image specified in the provided source info. If the component
|
||||
* is mounted, call setState() with the return value of this function. If the component has not yet mounted, use
|
||||
|
||||
Reference in new issue
Block a user