Skip to content

Commit

Permalink
fix(esl-carousel): fix initial rendering layout shift to eliminate CL…
Browse files Browse the repository at this point in the history
…S degradation

Closes: #2879

Co-authored-by: alesun <[email protected]>
  • Loading branch information
ala-n and NastaLeo committed Jan 23, 2025
1 parent 0210885 commit 7d65335
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,15 @@ export class ESLDefaultCarouselRenderer extends ESLCarouselRenderer {

public override redraw(): void {
this.resize();
// Calculate initial offset based on current rendered state (rendering shifts are not allowed)
const fallbackOffset = this.getOffset(this.getReserveCount());

this.reorder();
this.setActive(this.currentIndex);

// Set initial offset based on pre-calculation
this.setTransformOffset(-fallbackOffset);
// Update offset according to main algorithm (fix edge cases if the fallback offset is not correct)
this.setTransformOffset(-this.getOffset(this.currentIndex));
}

Expand Down

0 comments on commit 7d65335

Please sign in to comment.