fix(slideshow): stop on last slide in linear mode; reshuffle endlessly in shuffle mode#293
Merged
Merged
Conversation
…shuffle) The autoplay slideshow misbehaved at the end of the slide list: - Linear mode reaching the last image jumped back ~10 slides instead of stopping. Swiper's autoplay, on reaching the end with loop off, calls slideTo(0) — the first slide of the windowed in-memory buffer, not the album start. We now own end-of-list: when resolveOffset(+1) reports no next slide (genuine end, wrap off), the slideNextTransitionStart handler stops autoplay so the show rests on the last slide. stopOnLastSlide:true is kept as a config backstop for the start-while-already-on-last case. Wrap on continues to append the wrapped slide ahead and loops. - Shuffle mode on a small album showed every image once and then froze (indicator still "running") because the old random picker refused any image already loaded — once all were in the buffer, nothing could be appended. Replaced it with a reshuffling "bag": every image is dealt once per cycle in random order, then the bag refills and reshuffles for a fresh order, so shuffle runs indefinitely. A cross-cycle guard avoids immediate repeats. trimShuffleBacklog bounds the buffer (re-dealing would otherwise grow the DOM without limit) without stop/starting autoplay. Tests: reworked swiper-shuffle tests for the bag semantics and added end-of-list coverage (linear stop, wrap append, shuffle no-stall). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
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.
Problem
The autoplay slideshow misbehaved at the end of the slide list:
loop: false, callsslideTo(0)— which lands on the first slide of the windowed in-memory buffer (a subset, not the album's first image), so it appeared to leap backward.Fix
Linear end-of-list — We now own end-of-list behavior instead of relying on Swiper's autoplay. When
slideState.resolveOffset(+1)reports there is no next slide (genuine end of list, wrap off), theslideNextTransitionStarthandler stops autoplay so the slideshow rests on the last slide.stopOnLastSlide: trueis kept as a config backstop for the "start the slideshow while already parked on the last slide" case. With wrap on,resolveOffset(+1)returns the wrapped index, so the next slide is appended ahead and the slideshow loops to the start.Shuffle reshuffling deck — Replaced the "pick a random index not already loaded" logic with a reshuffling bag: every image is dealt exactly once per cycle in random order; when the bag empties it refills and reshuffles into a fresh order, so shuffle runs indefinitely. A cross-cycle guard prevents an image repeating twice in a row (including avoiding an immediate repeat of the on-screen image when shuffle first starts).
trimShuffleBacklogkeeps the buffer bounded by the high-water mark — re-dealing images across cycles would otherwise grow the DOM without limit — and does so without stop/starting autoplay (so the play/pause icon doesn't flicker every slide).Behavior after the fix
Testing
npm run lintandnpm run format:checkclean.🤖 Generated with Claude Code