Skip to content

fix(Collapsible, Accordion): don't play the open animation for content mounted open - #2209

Merged
huntabyte merged 1 commit into
mainfrom
fix/2039-mount-animation-race
Oct 20, 2026
Merged

huntabyte merged 1 commit into
mainfrom
fix/2039-mount-animation-race

Conversation

@huntabyte

Copy link
Copy Markdown
Owner

Summary

  • Fixes Mount-animation prevention races against rAF flag flip — Collapsible/Accordion slide on initial mount when open #2039: Collapsible.Content and Accordion.Content that mount open could play their open animation when the main thread was busy during mount.
  • Root cause: the animation block was set imperatively on the node (transitionDuration/animationName) and lifted in a requestAnimationFrame. Svelte rewrites the style attribute when props change (e.g. after measuring), which wiped the block. A slow frame could also lift it too early.
  • Adds MountAnimationGuard in internal/mount-animation.svelte.ts. It renders the block through the content's style prop, so Svelte's style updates can't remove it. It lifts on the first open state change, so later open and close still animate.
  • Adds measureWithoutAnimation, a shared helper that measures a node with animations blocked and then restores its inline styles. It replaces the duplicated measurement code in both components.
  • Removes the per-component #originalStyles / #isMountAnimationPrevented state and the rAF effects.
  • Adds a patch changeset for bits-ui.

Testing

  • Added browser tests collapsible-mount-animation.browser.test.ts and accordion-mount-animation.browser.test.ts:
    • Several items mounted open with a 50ms busy main thread fire no animationstart and have no running animations.
    • After mounting open, closing plays slide-up and reopening plays slide-down.
  • Not run: the new browser tests and the existing Collapsible/Accordion test suites were not run as part of writing this description.

- Add MountAnimationGuard to block animations via the content's style prop until the first open state change
- Add measureWithoutAnimation to measure dimensions and restore inline styles
- Use both in Collapsible and Accordion content, replacing the rAF-based prevention
- Add browser tests and a changeset
@changeset-bot

changeset-bot Bot commented Oct 20, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 8e1674e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
bits-ui Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@github-actions

github-actions Bot commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor
built with Refined Cloudflare Pages Action

⚡ Cloudflare Pages Deployment

Name Status Preview Last Commit
bits-ui ✅ Ready (View Log) Visit Preview 8e1674e

@huntabyte
huntabyte merged commit 57dc07b into main Oct 20, 2026
7 checks passed
@github-actions github-actions Bot mentioned this pull request Oct 20, 2026

This branch was successfully deployed

1 active deployment
Preview — 8e1674e7 Deployed Oct 20, 2026 by github-actions[bot]
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.

Mount-animation prevention races against rAF flag flip — Collapsible/Accordion slide on initial mount when open

1 participant