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

Add support for 'Passive event listeners' to improve page scroll performance #16

Open
evolve2k opened this issue Oct 10, 2018 · 3 comments

Comments

@evolve2k
Copy link

evolve2k commented Oct 10, 2018

Implementing a horizontal swipe using touch events with this library started producing this warning in our console:

Main.elm:8830 [Violation] Added non-passive event listener to a scroll-blocking 'touchmove' event. Consider marking event handler as 'passive' to make the page more responsive. See https://www.chromestatus.com/feature/5745543795965952

Further research brought us to this explanation on caniuse:

Event listeners created with the passive: true option cannot cancel (preventDefault()) the events they receive. Primarily intended to be used with touch events and wheel events. Since they cannot prevent scrolls, passive event listeners allow the browser to perform optimizations that result in smoother scrolling.

ref: https://caniuse.com/#feat=passive-event-listener

Our use case is that of having a scrollable list of items on a mobile device and that each item is the full width of the screen and is swipable. Here's an example (in JS) for illustration: http://jsfiddle.net/evolve2k/afkdtjh9/14/

We're interested in how we can utilise passive event listeners with this library.
Can you see a way of doing this?

@evolve2k evolve2k changed the title Add Support for Passive event listeners to improve page scroll performance Add Support for 'Passive event listeners' to improve page scroll performance Oct 10, 2018
@evolve2k evolve2k changed the title Add Support for 'Passive event listeners' to improve page scroll performance Add support for 'Passive event listeners' to improve page scroll performance Oct 10, 2018
@mpizenberg
Copy link
Owner

Oh I didn't know such issues could trigger runtime errors (is this an error or warning?). I've always used this library for "drawing" kind of events and so always needed to prevent mobile browser passive events handling like scrolling and such (which would mess with the drawing action).

I'll look into it more when I have a bit of time (might not be in the next two weeks). Thanks a lot for the report!

Meanwhile, I believe elm 0.19 automatically make events passive when we are not using preventDefault. Could you try using onWithOptions and setting the options to False. It might solve your issue if preventDefault is not needed.

@evolve2k
Copy link
Author

evolve2k commented Oct 10, 2018

Oh I didn't know such issues could trigger runtime errors (is this an error or warning?).

Ah yes it's only a warning. I'll update my post above.

I've always used this library for "drawing" kind of events and so always needed to prevent mobile browser passive events handling like scrolling and such (which would mess with the drawing action).
I'll look into it more when I have a bit of time (might not be in the next two weeks). Thanks a lot for the report!

Thank you!!

Meanwhile, I believe elm 0.19 automatically make events passive when we are not using preventDefault.

Interesting. Currently we're on 0.18, keen to upgrade soon though.

Could you try using onWithOptions and setting the options to False. It might solve your issue if preventDefault is not needed.

Cheers. We'll have a look and try with 2.0.1 as we're on 0.18

@mpizenberg
Copy link
Owner

Hi, I'm doing a little round of the open issues. I don't have enough time these days to try to maintain a 0.18 version. Did you, by any chance, try to update your gestures code to 0.19? Is it also producing this warning?

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