Skip to content

fix(core): avoid double-subtracting offsets in centerInsufficientSlides#8158

Merged
nolimits4web merged 1 commit intonolimits4web:masterfrom
avendiart:fix-double-offsets
Feb 13, 2026
Merged

fix(core): avoid double-subtracting offsets in centerInsufficientSlides#8158
nolimits4web merged 1 commit intonolimits4web:masterfrom
avendiart:fix-double-offsets

Conversation

@avendiart
Copy link
Copy Markdown
Contributor

Fix centerInsufficientSlides with slidesOffsetBefore/After in v12

Summary

In Swiper v12.0.0+, centerInsufficientSlides under-centers slides when slidesOffsetBefore and/or slidesOffsetAfter are set. The wrapper ends up shifted by (offsetBefore + offsetAfter) / 2 compared to v11 behavior. This PR fixes the centering math so offsets are applied exactly once.

Root cause

Starting in v12 (commit 74cc297), updateSlides() computes:

  • swiperSize = swiper.size - offsetBefore - offsetAfter

But the centerInsufficientSlides block still treated offsets as not accounted for and subtracted them again via offsetSize, effectively shrinking the available size by 2 * (offsetBefore + offsetAfter).

Reproduction

Minimal config:

new Swiper('.swiper', {
  slidesPerView: 'auto',
  spaceBetween: 12,
  centerInsufficientSlides: true,
  slidesOffsetBefore: 48,
  slidesOffsetAfter: 48,
});

Verification

  • With fewer slides than needed to fill the container, v12 now centers the same as v11 when offsets are configured.
  • No behavior change when offsets are 0 / unset.

@nolimits4web nolimits4web merged commit 60b0052 into nolimits4web:master Feb 13, 2026
@nolimits4web
Copy link
Copy Markdown
Owner

Merged, thank you!

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

Successfully merging this pull request may close these issues.

2 participants