Skip to content

Commit

Permalink
protect against reading removeEventListener from el if null (#4213)
Browse files Browse the repository at this point in the history
* protect against reading removeEventListener from el if null

* Added changeset

Co-authored-by: Eythor Gisli Thorsteinsson <eythort@menandmice.com>
Co-authored-by: Jed Watson <jed.watson@me.com>
Co-authored-by: Nathan Bierema <nbierema@gmail.com>
  • Loading branch information
4 people committed Dec 12, 2020
1 parent a0133f1 commit d1e660c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .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
2 changes: 2 additions & 0 deletions packages/react-select/src/internal/ScrollCaptor.js
Expand Up @@ -40,6 +40,8 @@ class ScrollCaptor extends Component<CaptorProps> {
}
}
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);
Expand Down

0 comments on commit d1e660c

Please sign in to comment.