Add {passive: true} to addEventListener
See original GitHub issueUsing perfect-scrollbar
in chrome produces a lot of Violation issues
zone-evergreen.js:1773 [Violation] Added non-passive event listener to a scroll-blocking event. Consider marking event handler as ‘passive’ to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952
adding {passive: true}
should resolve this issue
bind(eventName, handler) {
if (typeof this.handlers[eventName] === 'undefined') {
this.handlers[eventName] = [];
}
this.handlers[eventName].push(handler);
this.element.addEventListener(eventName, handler, {passive: true});
}
unbind(eventName, target) {
this.handlers[eventName] = this.handlers[eventName].filter(handler => {
if (target && handler !== target) {
return true;
}
this.element.removeEventListener(eventName, handler, {passive: true});
return false;
});
}
Issue Analytics
- State:
- Created 3 years ago
- Reactions:22
- Comments:8
Top Results From Across the Web
EventTarget.addEventListener() - Web APIs | MDN
The method addEventListener() works by adding a function, or an object that ... For the third parameter, if passiveSupported is true , we're ......
Read more >What are passive event listeners? - javascript - Stack Overflow
Passive event listeners are an emerging web standard, new feature shipped in Chrome 51 that provide a major potential boost to scroll performance....
Read more >Passive event listeners - Medium
Passive event listeners are an emerging web standard, new feature shipped in Chrome 51 and Firefox 49 that provide a major potential boost ......
Read more >Use passive listeners to improve scrolling performance
# How to make event listeners passive to improve scrolling performance. Add a passive flag to every event listener that Lighthouse identified.
Read more >Use passive listeners to improve scrolling performance
Adding a passive: true flag to the event listener tells the browser to allow page scrolling immediately, rather than wait for the script...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
This has already been PR-ed: https://github.com/mdbootstrap/perfect-scrollbar/pull/945
Apart from your proposed fix, it also uses feature detection, so it continues to work as intended on older browser versions, without support for the new syntax. Details here.
Also agree.