From d1e660c6b261d7fd60a85a6eca2ee9e3e0348ea2 Mon Sep 17 00:00:00 2001 From: eythort Date: Sat, 12 Dec 2020 14:27:01 +0000 Subject: [PATCH] protect against reading removeEventListener from el if null (#4213) * protect against reading removeEventListener from el if null * Added changeset Co-authored-by: Eythor Gisli Thorsteinsson Co-authored-by: Jed Watson Co-authored-by: Nathan Bierema --- .changeset/lemon-boats-cover.md | 5 +++++ packages/react-select/src/internal/ScrollCaptor.js | 2 ++ 2 files changed, 7 insertions(+) create mode 100644 .changeset/lemon-boats-cover.md diff --git a/.changeset/lemon-boats-cover.md b/.changeset/lemon-boats-cover.md new file mode 100644 index 0000000000..dd4afc9514 --- /dev/null +++ b/.changeset/lemon-boats-cover.md @@ -0,0 +1,5 @@ +--- +"react-select": patch +--- + +Added a guard to the `ScrollCaptor` component to check that `el` exists before calling `removeEventListener`, fixes intermittent errors diff --git a/packages/react-select/src/internal/ScrollCaptor.js b/packages/react-select/src/internal/ScrollCaptor.js index 1a37dd018f..17a7a82f1b 100644 --- a/packages/react-select/src/internal/ScrollCaptor.js +++ b/packages/react-select/src/internal/ScrollCaptor.js @@ -40,6 +40,8 @@ class ScrollCaptor extends Component { } } stopListening(el: HTMLElement) { + if (!el) return; + // all the if statements are to appease Flow 😢 if (typeof el.removeEventListener === 'function') { el.removeEventListener('wheel', this.onWheel, false);