fix(react): check for component unmount, fixes #19859

This commit is contained in:
Aubrey Holland 2019-11-07 15:20:36 -05:00 committed by Ely Lucas
parent 13b323f25d
commit 74e40cdc35
1 changed files with 5 additions and 2 deletions

View File

@ -23,6 +23,7 @@ export const createControllerComponent = <OptionsType extends object, OverlayTyp
return class extends React.Component<Props> {
overlay?: OverlayType;
isUnmounted = false;
constructor(props: Props) {
super(props);
@ -40,6 +41,7 @@ export const createControllerComponent = <OptionsType extends object, OverlayTyp
}
componentWillUnmount() {
this.isUnmounted = true;
if (this.overlay) { this.overlay.dismiss(); }
}
@ -60,8 +62,9 @@ export const createControllerComponent = <OptionsType extends object, OverlayTyp
attachProps(this.overlay, {
[dismissEventName]: onDidDismiss
}, prevProps);
// Check isOpen again since the value could of changed during the async call to controller.create
if (this.props.isOpen === true) {
// Check isOpen again since the value could have changed during the async call to controller.create
// It's also possible for the component to have become unmounted.
if (this.props.isOpen === true && this.isUnmounted === false) {
await this.overlay.present();
}
}