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

Default touch/wheel events to passive #1404

Closed
tigt opened this issue Aug 22, 2019 · 4 comments
Closed

Default touch/wheel events to passive #1404

tigt opened this issue Aug 22, 2019 · 4 comments

Comments

@tigt
Copy link
Contributor

tigt commented Aug 22, 2019

Description

This is an optimization that Svelte does to be fast by default, and it seems worth stealing:

passive — improves scrolling performance on touch/wheel events (Svelte will add it automatically where it's safe to do so)

— Events / Event modifiers • Svelte Tutorial

Why

Many times when you encounter scroll jank, the culprit is a touch event listener. Touch event listeners are often useful for tracking user interactions and creating custom scroll experiences, such as cancelling the scroll altogether when interacting with an embedded Google Map. Currently, browsers can't know if a touch event listener is going to cancel the scroll, so they always wait for the listener to finish before scrolling the page. Passive event listeners solve this problem by enabling you to set a flag in the options parameter of addEventListener indicating that the listener will never cancel the scroll. That information enables browsers to scroll the page immediately, rather than after the listener has finished.

— Improving Scroll Performance with Passive Event Listeners

Possible Implementation & Open Questions

Is this something you're interested in working on?

Yes

@x4080
Copy link

x4080 commented Sep 4, 2020

Hi, is this what lighthouse warning about ? And is it already implemented yet ?

Thanks

@tigt
Copy link
Contributor Author

tigt commented Sep 5, 2020

Yes, I think this is one and the same.

Does not use passive listeners to improve scrolling performance:

Touch and wheel event listeners are useful for tracking user interactions and creating custom scrolling experiences, but they can also delay page scrolling. Currently, browsers can't know if an event listener will prevent scrolling, so they always wait for the listener to finish executing before scrolling the page. Passive event listeners solve this problem by letting you indicate that an event listener will never prevent scrolling.

Unfortunately, no, it is not implemented yet, nor the functionality to manually set such listeners to passive (#1408). You can remove the warning by bypassing the onEvent= attribute name shortcuts and instead getting a ref and attaching event listeners the old-fashioned way.

@x4080
Copy link

x4080 commented Sep 5, 2020

@tigt Thanks

@DylanPiercey
Copy link
Contributor

I think this is largely a duplicate of #1408

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

3 participants