Skip to content

fix(carousel): time autoplay with a per-panel animation and pause it on hover - #3347

Merged
interactivellama merged 2 commits into
masterfrom
fix/carousel-autoplay-dwell-timer
Nov 20, 2026
Merged

interactivellama merged 2 commits into
masterfrom
fix/carousel-autoplay-dwell-timer

Conversation

@interactivellama

@interactivellama interactivellama commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Fixes the flaky components/carousel/__tests__/carousel.browser.test.jsx autoplay tests, which have failed intermittently across the 11.0.0-rc.1 stack and on master (runs 44588632552, 44421155026, 44417854821, 44205040933, 44184736972, 44002779596, 42139457771).

Additional description

Root cause. Autoplay ran on a free-running setInterval that started inside render()'s act(). The tests sampled on their own clock, started after render() returned, with half an interval (±50ms) of slack. Forced layout (offsetWidth, heavier with the SLDS 2 CSS) and CI load pushed the two clocks a tick apart, so each failure is a correct panel sequence shifted by one tick (for example [0, -624, -936, 0, -312] for [0, -312, -624, -936, 0]). The component's panel order was always right; the test raced it.

Fix. Autoplay now times each panel with a keyframe-less Web Animations animation on the stage, started by an effect after each committed panel:

  • A step never acts on a panel that hasn't rendered, and manual or controlled panel changes restart the dwell.
  • It pauses while the pointer is over the carousel or the tab is hidden, and resumes with the remaining time (WCAG 2.2.2). The document timeline keeps running in a hidden tab, so a visibilitychange listener does the pausing there. pointermove also counts as hovering, which covers a carousel that mounts under the pointer and never gets pointerenter.
  • Without the Web Animations API (jsdom), it falls back to one setTimeout per panel.

The browser tests step autoplay with Animation.finish() and wait for the next dwell, so no wall clock is involved. New tests cover the hover pause, a pointer already over the carousel, and the hidden-tab pause. The test picks the dwell by its duration, not by taking the stage's first animation.

Behavior change: autoplay pauses while hovered or while the tab is hidden. Previously it kept advancing under the pointer, and on return to a background tab it advanced straight away.

Verification

  • The browser test file passed 20/20 runs in a row locally.
  • With a 150ms busy-wait injected after render(): the new tests pass, and the old tests on master fail 5/13 the same way CI does.
  • Calling the first render's (stale) step fails the four translation tests. Removing the hover pause fails both hover tests. Removing the visibilitychange listener or the pointermove handler each fails its new test.
  • npm run test:ci is green on this branch, and on the restacked rc.1 stack.

This sits at the base of the 11.0.0-rc.1 stack, under #3345, so every PR in the milestone picks it up.


CONTRIBUTOR checklist (do not remove)

Please complete for every pull request.

Green gate — all of these must pass locally (CI runs the same):

  • npm run lint passes with 0 errors and 0 warnings (npm run lint:fix to auto-fix). No new warnings: the carousel has the same 5 as master.
  • npm run typecheck is clean (tsc --noEmit).
  • npm test -- --run passes — this runs both Vitest projects (jsdom unit + real-browser browser) and the story HTML snapshots. If you changed rendered markup on purpose, update snapshots with npm test -- --run -u and review the diff.
  • npm run build succeeds (type-check + Vite library build + .d.ts + entry shims).

Behavior & docs:

  • First-time contributors: sign the CLA (a bot will comment with instructions).
  • Added/updated Vitest + React Testing Library tests for the change (template: components/button/__tests__). New props and bug fixes should get a regression test. Tests that genuinely need a real browser (focus traversal, layout/measurement, canvas) go in a *.browser.test.jsx file (the browser project); everything else is jsdom.
  • Reviewed the component's Storybook stories: npm run storybook → http://localhost:6007/. Confirm the story actually renders and behaves (deprecated Storyshots/Karma are gone; there is no separate browser-tests server). Not yet checked by hand: Carousel › With Autoplay, hover pause.
  • Story/example code uses the component's real prop API (e.g. slots like content / visualPickerFigure, render props like renderItem, icon props, events), not assumptions — a common source of "component looks broken" reports has been stories authored against the wrong API. Cross-check against components/<name>/__examples__. No story changes.
  • Storybook Accessibility (a11y) panel shows no new violations for the affected stories. No markup changed, but not checked.
  • If you added or changed a type, remember runtime PropTypes were removed in the TS migration — types are the contract. Ship accurate .d.ts (they're generated by the build); JS consumers rely on them via editor type-acquisition. Only the JSDoc on autoplayInterval and hasAutoplay changed.

REVIEWER checklist (do not remove)

  • CI is green (GitHub Actions CI workflow: lint, typecheck, test, build). Chromatic visual review, if configured, has been checked.
  • Change has adequate test coverage; bug fixes include a regression test.
  • Reviewed the affected Storybook stories and their a11y panels.
  • Rendered markup still conforms to SLDS — check the story HTML snapshot diff (components/__tests__/__snapshots__/story-snapshots.test.jsx.snap).
  • Public API / package surface: if exports changed, the deep-import contract still holds (@salesforce/design-system-react/components/<name> and nested paths resolve for ESM, CJS, and types). Removing/renaming a public component or export is a breaking change → feat!:/BREAKING CHANGE: and a major version bump.

…on hover

The autoplay browser tests failed intermittently in CI, each time one
panel ahead of the expected sequence. Autoplay ran on a free-running
setInterval that started inside render()'s act(), while the tests sampled
on their own clock started after render() returned, with half an interval
of slack. Forced layout and CI load pushed the two clocks a tick apart.

Autoplay now times each panel with a keyframe-less Web Animations
animation on the stage, started by an effect after each committed panel,
so a step never acts on a panel that hasn't rendered. The animation runs
on the document timeline, so it pauses in a hidden tab, and it pauses
while the pointer is over the carousel (WCAG 2.2.2), resuming with the
remaining time. Without the Web Animations API (jsdom) a setTimeout per
panel is used instead.

The browser tests step autoplay with Animation.finish() and wait for the
next dwell, so no wall clock is involved. New tests cover the hover pause.
@interactivellama interactivellama added this to the 11.0.0-rc.1 milestone Nov 19, 2026
…already-present pointer

The document timeline keeps running in a hidden tab, so the dwell finished
as soon as the tab was shown again instead of resuming with the time it had
left. Pause it on visibilitychange. A carousel that mounts under the pointer
gets no pointerenter, so pointermove now also marks the pointer as over it.
The browser test picks the dwell by its duration rather than taking the
stage's first animation.
@interactivellama
interactivellama merged commit 0acc51a into master Nov 20, 2026
7 checks passed
@interactivellama
interactivellama deleted the fix/carousel-autoplay-dwell-timer branch November 20, 2026 23:37
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