shoelace-style / shoelace

A collection of professionally designed, every day UI components built on Web standards. SHOELACE IS BECOMING WEB AWESOME 👇👇👇
https://webawesome.com
MIT License
12.96k stars 833 forks source link

sl-carousel goToSlide has synchronous layout #2280

Open patrick-mcdougle opened 1 day ago

patrick-mcdougle commented 1 day ago

Describe the bug

The initial render of the sl-carousel calls the initialize slides function which calls goToSlide. goToSlide uses getBoundingClientRect to determine the geometry of the slides to know how far to scroll them. This is fine in the case that your app is rendering 1 carousel, but components that render many carousels suffer from having a lot of synchronous layouts in a row. For example, on Rothy's collection pages, each of our product cards has a sl-carousel on them.

To Reproduce

  1. Have multiple carousels on one page (and mount them all in the same tick)
  2. Perform a performance capture on page load
  3. See that each of the carousels has a forced relayout

Screenshots

Legible Flamechart

Screenshot 2024-11-22 at 4 00 21 PM

Zooming out we have 100 carousels!

Screenshot 2024-11-22 at 4 00 41 PM

Browser / OS

Additional information

https://web.dev/articles/avoid-large-complex-layouts-and-layout-thrashing https://gist.github.com/paulirish/5d52fb081b3570c81e3a

patrick-mcdougle commented 1 day ago

In the process of making a PR.

claviska commented 1 day ago

Thanks for the issue, and for taking a stab at a PR!