Skip to content

Commit

Permalink
fix(react): check for component unmount, fixes #19859
Browse files Browse the repository at this point in the history
  • Loading branch information
aub authored and Ely Lucas committed Nov 7, 2019
1 parent de0a899 commit 7356c40
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions packages/react/src/components/createControllerComponent.tsx
Expand Up @@ -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);
Expand All @@ -40,6 +41,7 @@ export const createControllerComponent = <OptionsType extends object, OverlayTyp
}

componentWillUnmount() {
this.isUnmounted = true;
if (this.overlay) { this.overlay.dismiss(); }
}

Expand All @@ -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();
}
}
Expand Down

0 comments on commit 7356c40

Please sign in to comment.