Skip to content

Carousel: autoplay stalls after one panel and slides lag behind the active panel #3271

Closed

Description

@interactivellama

Summary

In 11.0.0-alpha.*, Carousel autoplay stops after one panel, and the slides stay put or lag one click behind the indicators when navigating with the previous/next buttons, the indicators, or the arrow keys. Reproduces with itemsPerPanel 1 and 3. The 10.x class component did not have either bug.

Steps to reproduce

  1. Render <Carousel items={...} hasAutoplay isInfinite autoplayInterval={3000} /> (the WithAutoplay story) and turn autoplay on.
  2. Watch the indicators: they advance to panel 2 (index 1), then stay there. With real timing the slides can also stay on the first panel after the first loop.
  3. Render the ThreeItemsPerPanel story with hasPreviousNextPanelNavigation and click the next button. The indicator moves to panel 2 but the slides don't. The next click shows panel 2's slides, one click behind.

Expected

Autoplay advances through every panel and loops when isInfinite is set. The slides always show the active panel.

Root cause

Both come from the hooks rewrite in #3195 (520f86bb7). The class component read this.getCurrentPanel() live; the rewrite uses closures that go stale.

  • The setInterval callback in startAutoplay closes over currentPanel, nrOfPanels and isInfinite from the render where autoplay started, so every tick re-selects panel 1.
  • setCurrentPanel runs changeTranslationAutomatically in a setTimeout. That callback holds the previous panel and writes the previous translateX after the effect sets the new one.

Neither was caught: no test let an interval fire, jsdom reports offsetWidth as 0, and fake timers inside act() hide the ordering.

Environment

Any 11.0.0 alpha that includes the hooks rewrite (#3195), including 11.0.0-alpha.6; React 19.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions