Skip to content

Commit 8b8c22f

Browse files
authored
Merge pull request #131 from STRML/passiveRemove
Check eventListener 'options' support & use same passive arg for removal
2 parents 877ceb3 + 57bcba5 commit 8b8c22f

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

react-list.es6

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,22 @@ const SIZE_KEYS = {x: 'width', y: 'height'};
2323

2424
const NOOP = () => {};
2525

26-
const PASSIVE = {passive: true};
26+
// If a browser doesn't support the `options` argument to
27+
// add/removeEventListener, we need to check, otherwise we will
28+
// accidentally set `capture` with a truthy value.
29+
const PASSIVE = (() => {
30+
if (typeof window === 'undefined') return false;
31+
let hasSupport = false;
32+
try {
33+
document.createElement('div').addEventListener('test', NOOP, {
34+
get passive() {
35+
hasSupport = true;
36+
return false;
37+
}
38+
});
39+
} catch (e) {}
40+
return hasSupport;
41+
}() ? {passive: true} : false;
2742

2843
module.exports = class ReactList extends Component {
2944
static displayName = 'ReactList';
@@ -87,8 +102,8 @@ module.exports = class ReactList extends Component {
87102

88103
componentWillUnmount() {
89104
window.removeEventListener('resize', this.updateFrame);
90-
this.scrollParent.removeEventListener('scroll', this.updateFrame);
91-
this.scrollParent.removeEventListener('mousewheel', NOOP);
105+
this.scrollParent.removeEventListener('scroll', this.updateFrame, PASSIVE);
106+
this.scrollParent.removeEventListener('mousewheel', NOOP, PASSIVE);
92107
}
93108

94109
getOffset(el) {

0 commit comments

Comments
 (0)