question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Add {passive: true} to addEventListener

See original GitHub issue

Using 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:open
  • Created 3 years ago
  • Reactions:22
  • Comments:8

github_iconTop GitHub Comments

3reactions
andrei-gheorghiucommented, Nov 22, 2020

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.

3reactions
NonieBenkscommented, Oct 15, 2020

Also agree.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found