Skip to content

Commit

Permalink
BUGFIX: make setState handling more robust in ImageEditor to prevent …
Browse files Browse the repository at this point in the history
…warning if unmounted (needed to have the tests run through)
  • Loading branch information
skurfuerst committed Sep 13, 2024
1 parent 38bd6a1 commit 28bf36c
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions packages/neos-ui-editors/src/Editors/Image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ export default class ImageEditor extends Component {
isAssetLoading: true
}, () => {
this.loadImage = loadImageMetadata(this.props.value.__identity).then(image => {
this.setState({image, isAssetLoading: false});
if (this._isMounted) {
this.setState({image, isAssetLoading: false});
}
});
});
}
Expand All @@ -88,7 +90,9 @@ export default class ImageEditor extends Component {
const {loadImageMetadata} = backend.get().endpoints;

if (!nextProps.value || !nextProps.value.__identity) {
this.setState({image: null});
if (this._isMounted) {
this.setState({image: null});
}
}

//
Expand All @@ -101,14 +105,16 @@ export default class ImageEditor extends Component {
image,
isAssetLoading: false
}, () => {
// When forceCrop option is enabled and we were requested to do the force cropping...
if (this.state.requestOpenImageCropper && $get('crop.aspectRatio.forceCrop', this.props.options)) {
this.handleCloseSecondaryScreen();
this.handleOpenImageCropper();
this.setState({requestOpenImageCropper: false});
} else if (this.state.isImageCropperOpen) {
this.handleCloseSecondaryScreen();
this.handleOpenImageCropper();
if (this._isMounted) {
// When forceCrop option is enabled and we were requested to do the force cropping...
if (this.state.requestOpenImageCropper && $get('crop.aspectRatio.forceCrop', this.props.options)) {
this.handleCloseSecondaryScreen();
this.handleOpenImageCropper();
this.setState({requestOpenImageCropper: false});
} else if (this.state.isImageCropperOpen) {
this.handleCloseSecondaryScreen();
this.handleOpenImageCropper();
}
}
});
}
Expand Down

0 comments on commit 28bf36c

Please sign in to comment.