Skip to content

Commit 28cd140

Browse files
author
Christopher Willis-Ford
committed
Cancel ScratchImage load if unmounted
1 parent 5f6b89e commit 28cd140

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/components/scratch-image/scratch-image.jsx

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,13 @@ class ScratchImage extends React.PureComponent {
3939
storage
4040
.load(imageSource.assetType, imageSource.assetId)
4141
.then(asset => {
42-
const dataURI = asset.encodeDataURI();
43-
nextImage.setState({
44-
imageURI: dataURI
45-
});
42+
if (!nextImage.wasUnmounted) {
43+
const dataURI = asset.encodeDataURI();
44+
45+
nextImage.setState({
46+
imageURI: dataURI
47+
});
48+
}
4649
--this._currentJobs;
4750
this.loadPendingImages();
4851
});
@@ -58,6 +61,10 @@ class ScratchImage extends React.PureComponent {
5861
const newState = this._loadImageSource(nextProps.imageSource);
5962
this.setState(newState);
6063
}
64+
componentWillUnmount () {
65+
this.wasUnmounted = true;
66+
ScratchImage._pendingImages.delete(this);
67+
}
6168
/**
6269
* Calculate the state changes necessary to load the image specified in the provided source info. If the component
6370
* is mounted, call setState() with the return value of this function. If the component has not yet mounted, use

0 commit comments

Comments
 (0)