fix(core): Don't use data-swiper-slide-index for realIndex when virtual module is enabled#8142
Merged
nolimits4web merged 1 commit intonolimits4web:masterfrom Jan 28, 2026
Merged
Conversation
…irtual module is enabled
Owner
|
Merged, thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Swiper has virtual and thumbnail modules, which can be used to create an image carousel with thumbnails.
Issue
When both modules are enabled:
Image carousel scrolls to slide 9.
Thumbnail carousel scrolls to slide 9
Image carousel scrolls to slide 2.
Currently: Thumbnail carousel scrolls back to slide 9.
Expected: Thumbnail carousel scrolls to slide 2.
The issue occurs only on the first set of slides.
Slides 6 and after work as expected.
reproduction.mp4
Html playground
Copy to
playground/core/index.htmlStack trace
When viewing slide 9. Then clicking on slide 2, which has an index of 1:
onThumbClick:
slideToIndex= 1skip= 0,snapIndex= 1,snapGrid.length= 50slideTo: slideIndex = 1
swiper.setTranslate(translate)-> emitssetTranslatesetTranslatelistener in virtual.mjs:update()
swiper.updateActiveIndex()
updateActiveIndex: (in
else if (swiper.slides[activeIndex]) {)activeIndex= 1swiper.slides[activeIndex]=<div class="image-slide swiper-slide swiper-slide-active" data-swiper-slide-index="8" style="left: 5460px; width: 770px; margin-right: 10px;">slideIndex= 8.realIndex= 8, fromdata-swiper-slide-index🔵 Slide dom node and
data-swiper-slide-indexhaven't been updated yet in dom.User clicked on slide 2, not 8
updateActiveIndexemitsslideChangethumbs.mjsscrolls the thumbnails carousel to slide with index = 8:update()swiper.realIndex= 8,thumbsToActivate= 1newThumbsIndex= 8Swiper reads
data-swiper-slide-indexafter commit f5a0ba8a.After commit d23e8094 in
updateActiveIndex()swiper handles virtual module's loop mode as a special case.In this PR
In
updateActiveIndexsetrealIndex = activeIndexif virtual module is enabled.Index in
data-swiper-slide-indexisn't up to date