-
-
Notifications
You must be signed in to change notification settings - Fork 771
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
Fix non-passive event listener on Chrome #264
Conversation
Implement recommended practice by enabling passive events.
Fix EventsBinder test to expect Object instead of Boolen
@jedrzejchalubek, I also modified the EventsBinder test to pass Cheers 🍻 |
Changes have been introduced very well :) However there is one problem that blocks me from adding passive events - browser support. Unfortunatly, passive events are not supported in IE11 version which this library needs to support for now. These need to wait until we drop support for IE11 😢
I've actually answered wongly in this issue. My bad. |
* Check if the browser supports passive events * Revert the EventsBinder test to expect Boolean
Yeah, I tried my change in IE11. And the drag event doesn't work smoothly, it keeps sticking to the cursor even when I don't click/hold the mouse. Then, I tried to add browser's passive event support detection as suggested in MDN web docs and implemented in detect-passive-events. Now the passive event listener only enabled if the browser supports it. I have tried to test it in IE11 on Windows 10, and it works for me. You can test it, and let me know if I need to refactor the code (newbie here 😁). Cheers 🍻 |
Oh, Great :) 🎉 One thing I would recommend here. Let's move an entire try-catch validation to a utility function named something like With this, we actually decouple this fallback and make it easier, later on, to refactor if we actually drop support for IE11. |
Yeah that's good idea. Also I would add it's probably good idea to "cache" the result of it so any subsequent calls to |
This is what I use in my app, just runs once and exports a boolean true/false so you can import it and re-use it wherever. Maybe it's useful? detect-passive-events.jsvar supportsPassive = false;
var opts = Object.defineProperty && Object.defineProperty({}, 'passive', {
get: function() {
supportsPassive = true;
}
});
document.addEventListener('test', function() {}, opts);
export default supportsPassive; Usageimport supportsPassive from './detect-passive-events';
panel.addEventListener('touchstart', function(eve) { }, supportsPassive ? { passive: true } : {}); |
I have made latest adjustments to this feature and it's going to the next release :) Thanks for your input @bianpratama @garygreen 💯 |
Implement recommended practice by enabling passive events. This is related to #245 by @antonlukin. Somehow, with
v3.2.3
I still get the warning:Tried to add the passive event listener in
event-binder.js
, and it successfuly removes the warning.