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

Yield on LiteYTEmbed click listener to reduce INP impact #180

Open
gilbertococchi opened this issue May 5, 2024 · 3 comments
Open

Yield on LiteYTEmbed click listener to reduce INP impact #180

gilbertococchi opened this issue May 5, 2024 · 3 comments

Comments

@gilbertococchi
Copy link

gilbertococchi commented May 5, 2024

RUM data on some project I have suggested that "lite-youtube.lyt-activated>button.lty-playbtn" interaction is causing large INP.

I would suggest yielding on the Click Event Handler doing something similar to this and improve the UX somehow like changing the Playback icon status etc to improve UX on top of INP.

this.addEventListener('click', function(event) {
            event.preventDefault();
            requestAnimationFrame(() => {
                setTimeout(() => {
                  if (this.classList.contains('lyt-activated')) return;
                  ...
@gilbertococchi
Copy link
Author

gilbertococchi commented May 5, 2024

Before Code Change (Note that code is happening in the YT Iframe Thread)
before

After Code Change
after

@paulirish
Copy link
Owner

Hmm.. Those look like other folks' event listeners.

Here's what that initial click on the play button looks like to me.. just a 20ms interaction:

image

@gilbertococchi
Copy link
Author

I have RUM data that suggests it's caused by YT iFrame main thread code triggered by the play-btn click event with target attribution, no other event handlers.

It's the YouTube Iframe Thread code that increased the play-btn Click Event Handler blocking time.

It's true that my lite-youtube-embed fork acts differently, loading the YT Iframe in the background, so it's much faster to start playback.

I should have fixed it by adding the yield code to the Click event listener as described, will update you once I get new daily data.
Screenshot 2024-05-06 at 21 22 59

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