[Maps][File upload] Fix "component-not-mounted" errors on cancel mid-way through indexing (#47090) (#47243)

* Check for component mounted before state updates occurring at cancel stopping points

* Remove redundant mounted check
This commit is contained in:
Aaron Caldwell 2019-10-03 11:33:27 -06:00 committed by GitHub
parent 91209659d5
commit 0b623fc42f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 1 deletions

View file

@ -65,6 +65,14 @@ export class JsonUploadAndParse extends Component {
indexPatternResp: '',
};
componentDidMount() {
this._isMounted = true;
}
componentWillUnmount() {
this._isMounted = false;
}
_resetFileAndIndexSettings = () => {
if (this.props.onFileRemove && this.state.fileRef) {
this.props.onFileRemove(this.state.fileRef);
@ -86,7 +94,11 @@ export class JsonUploadAndParse extends Component {
this._setSelectedType(this.state);
this._setIndexReady({ ...this.state, ...this.props });
this._indexData({ ...this.state, ...this.props });
if (this.props.isIndexingTriggered && !this.state.showImportProgress) {
if (
this.props.isIndexingTriggered &&
!this.state.showImportProgress &&
this._isMounted
) {
this.setState({ showImportProgress: true });
}
}
@ -131,6 +143,10 @@ export class JsonUploadAndParse extends Component {
parsedFile, transformDetails, indexName, selectedIndexType, appName
);
if (!this._isMounted) {
return;
}
// Index error
if (!indexDataResp.success) {
this.setState({
@ -158,6 +174,9 @@ export class JsonUploadAndParse extends Component {
}
// Indexing complete, update state & callback (if any)
if (!this._isMounted || !indexPatternResp) {
return;
}
this.setState({
currentIndexingStage: INDEXING_STAGE.INDEX_PATTERN_COMPLETE
});
@ -170,12 +189,18 @@ export class JsonUploadAndParse extends Component {
}
_createIndexPattern = async ({ indexName }) => {
if (!this._isMounted) {
return;
}
this.setState({
indexPatternRequestInFlight: true,
currentIndexingStage: INDEXING_STAGE.CREATING_INDEX_PATTERN
});
const indexPatternResp = await createIndexPattern(indexName);
if (!this._isMounted) {
return;
}
this.setState({
indexPatternResp,
indexPatternRequestInFlight: false,

View file

@ -25,6 +25,14 @@ export class AddLayerPanel extends Component {
layerImportAddReady: false,
}
componentDidMount() {
this._isMounted = true;
}
componentWillUnmount() {
this._isMounted = false;
}
componentDidUpdate() {
if (!this.state.layerImportAddReady && this.props.isIndexingSuccess) {
this.setState({ layerImportAddReady: true });
@ -48,6 +56,9 @@ export class AddLayerPanel extends Component {
}
_viewLayer = async (source, options = {}) => {
if (!this._isMounted) {
return;
}
if (!source) {
this.setState({ layer: null });
this.props.removeTransientLayer();
@ -60,6 +71,9 @@ export class AddLayerPanel extends Component {
style: style
};
const newLayer = source.createDefaultLayer(layerInitProps, this.props.mapColors);
if (!this._isMounted) {
return;
}
this.setState(
{ layer: newLayer },
() => this.props.viewLayer(this.state.layer)
@ -67,6 +81,11 @@ export class AddLayerPanel extends Component {
};
_clearLayerData = ({ keepSourceType = false }) => {
if (!this._isMounted) {
return;
}
this.setState({
layer: null,
...(