From 949839dcc323af1ba809098757694d172cf23e91 Mon Sep 17 00:00:00 2001 From: Nathan Reese Date: Thu, 13 Dec 2018 10:16:40 -0700 Subject: [PATCH] fix EuiSuperSelect from accessing ref when unmounted (#1369) * fix EuiSuperSelect from accessing ref when unmounted * change log --- CHANGELOG.md | 1 + src/components/form/super_select/super_select.js | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8877a2e9bf..2253882cfbb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ - Added `anchorClassName` prop to `EuiPopover` ([#1367](https://github.com/elastic/eui/pull/1367)) - Added support for `fullWidth` on `EuiSuperSelect` ([#1367](https://github.com/elastic/eui/pull/1367)) - Applied new scrollbar customization for Firefox ([#1367](https://github.com/elastic/eui/pull/1367)) +- Fixed `EuiSuperSelect` from accessing ref when unmounted ([1369](https://github.com/elastic/eui/pull/1369)) ## [`5.7.0`](https://github.com/elastic/eui/tree/v5.7.0) diff --git a/src/components/form/super_select/super_select.js b/src/components/form/super_select/super_select.js index 1876178bcad..41ef0b05d73 100644 --- a/src/components/form/super_select/super_select.js +++ b/src/components/form/super_select/super_select.js @@ -24,6 +24,14 @@ export class EuiSuperSelect extends Component { }; } + componentDidMount() { + this._isMounted = true; + } + + componentWillUnmount() { + this._isMounted = false; + } + setItemNode = (node, index) => { this.itemNodes[index] = node; }; @@ -48,6 +56,9 @@ export class EuiSuperSelect extends Component { ); requestAnimationFrame(() => { + if (!this._isMounted) { + return; + } this.setState({ menuWidth: this.popoverRef.getBoundingClientRect().width - 2, // account for border not inner shadow });