Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support passive event #42

Closed
yurited opened this issue Dec 29, 2016 · 3 comments
Closed

support passive event #42

yurited opened this issue Dec 29, 2016 · 3 comments

Comments

@yurited
Copy link

yurited commented Dec 29, 2016

a big/computation intensive touchStart, touchMove handler could block following scroll event.

Developers can now annotate touch and wheel listeners with {passive: true} to indicate that they will never invoke preventDefault. This feature shipped in Chrome 51, Firefox 49 and landed in WebKit.

in Chrome for Android 80% of the touch events that block scrolling never actually prevent it. 10% of these events add more than 100ms of delay to the start of scrolling, and a catastrophic delay of at least 500ms occurs in 1% of scrolls.

spec:
https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
https://developer.mozilla.org/en-US/docs/Web/API/EventTarget/addEventListener
https://dom.spec.whatwg.org/#dom-eventlisteneroptions-passive

scroll performance comparison between passive:true and false
https://www.youtube.com/watch?v=NPM6172J22g

polyfill

// Test via a getter in the options object to see 
// if the passive property is accessed
var supportsPassive = false;
try {
  var opts = Object.defineProperty({}, 'passive', {
    get: function() {
      supportsPassive = true;
    }
  });
  window.addEventListener("test", null, opts);
} catch (e) {}

// Use our detect's results. 
// passive applied if supported, capture will be false either way.
elem.addEventListener(
  'touchstart',
  fn,
  supportsPassive ? { passive: true } : false
); 

react is yet to support passive event
facebook/react#6436

@redonkulus
Copy link
Collaborator

@yurited you want to PR this?

@yurited
Copy link
Author

yurited commented Dec 29, 2016

yes

@redonkulus
Copy link
Collaborator

Fixed via #44

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants