Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

do not call setState if combo box is no longer mounted #807

Merged
merged 3 commits into from
May 9, 2018

Conversation

nreese
Copy link
Contributor

@nreese nreese commented May 8, 2018

fixes #794

I could not find a way to reproduce calling setState once the combo box component had been unmounted. This PR just avoids the potential of calling setState for 2 places where setState was called asynchronously.

@nreese nreese requested review from chandlerprall and timroes May 8, 2018 15:58
@chandlerprall
Copy link
Contributor

LGTM

@@ -483,6 +489,8 @@ export class EuiComboBox extends Component {
}

componentWillUnmount() {
this.incrementActiveOptionIndex.cancel;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you want to call cancel actually :-) .cancel()

@@ -74,6 +74,8 @@ export class EuiComboBox extends Component {
this.searchInput = undefined;
this.optionsList = undefined;
this.options = [];

this._hasUnmounted = false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since a component will also be in an unmounted state when initialized, I would rather recommend, having a variable _isMounted, that is false by default, will be set to true, when the component is mounted, and set to false again when the component will unmount, e.g. see also this comment.

But this is more theoretical, since we can be pretty sure, that updateListPosition will never be called before we mounted, so I leave this decision up to you :-)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought componentWillMount was getting deprecated in react 16.3. How would _isMounted get set to true without componentWillMount?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think componentDidMount should do the trick here, since there is also nothing you can do in componentWillMount anymore that should triggers the promise load.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this component tracks a ref to its top-level div you could instead check if this. comboBox is null or not, as React sets the ref on mount and re-executes the ref function again with null on unmount. They're all equally as hacky IMO.

@nreese nreese merged commit 895f2ca into elastic:master May 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EuiComboBox should not update when not mounted
3 participants