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

[useScrollTrigger] Make it scroll event handler passive #32437

Closed
2 tasks done
djfarly opened this issue Apr 23, 2022 · 4 comments · Fixed by #33749
Closed
2 tasks done

[useScrollTrigger] Make it scroll event handler passive #32437

djfarly opened this issue Apr 23, 2022 · 4 comments · Fixed by #33749
Labels
good first issue Great for first contributions. Enable to learn the contribution process. hook: useScrollTrigger package: material-ui Specific to @mui/material

Comments

@djfarly
Copy link

djfarly commented Apr 23, 2022

Duplicates

  • I have searched the existing issues

Latest version

  • I have tested the latest version

Summary 💡

Google Page Speed Insights warns about scroll event listeners not being passive.
So maybe the scroll event listener in useScrollTrigger should be passive? As long as there is no reason for it not to be?

I can make a PR but I do not want to do it if there is actually a reason for the event listener not to be passive. :)

Examples 🌈

https://github.com/mui/material-ui/blob/master/packages/mui-material/src/useScrollTrigger/useScrollTrigger.js#L34-L37

    target.addEventListener('scroll', handleScroll, { passive: true });
    return () => {
      target.removeEventListener('scroll', handleScroll, { passive: true });
    };

Screenshot 2022-04-23 at 23 11 51

Motivation 🔦

Just want to have one less thing to worry about in page speed insights 😁

@djfarly djfarly added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 23, 2022
@djfarly
Copy link
Author

djfarly commented Apr 23, 2022

Oh and by the way this is the article about passive event handlers.
https://web.dev/uses-passive-event-listeners/

@danilo-leal danilo-leal changed the title Make useScrollTrigger scroll event handler passive [useScrollTrigger] Make it scroll event handler passive Apr 26, 2022
@danilo-leal danilo-leal added hook: useScrollTrigger package: base-ui Specific to @mui/base new feature New feature or request labels Apr 26, 2022
@siriwatknp siriwatknp removed the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Apr 27, 2022
@michaldudak michaldudak added package: material-ui Specific to @mui/material and removed package: base-ui Specific to @mui/base labels Aug 1, 2022
@michaldudak
Copy link
Member

I don't see any reason for not having the event marked as passive. This issue is good to take.

@michaldudak michaldudak added the good first issue Great for first contributions. Enable to learn the contribution process. label Aug 1, 2022
@Dsalazar1685
Copy link
Contributor

I'd be happy to take this one.

@oliviertassinari
Copy link
Member

oliviertassinari commented Aug 2, 2022

any reason for not having the event marked as passive.

Could this create layout issues? It makes it possible for the scroll and the displayed elements to be out of sync. If React setstate triggers the paint in an asynchronous fashion, then we don't have this timing guaranteed anyway.

Why not move forward, the UX aspect is likely marginal and the DX win with less noise sound good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Great for first contributions. Enable to learn the contribution process. hook: useScrollTrigger package: material-ui Specific to @mui/material
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants