diff --git a/src/components/scratch-image/scratch-image.jsx b/src/components/scratch-image/scratch-image.jsx index 0727fe5d8..15abe9d3f 100644 --- a/src/components/scratch-image/scratch-image.jsx +++ b/src/components/scratch-image/scratch-image.jsx @@ -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