Fix animation replay and playback speed correctness - #76
Conversation
Replaying a finished MainThreadAnimation rebuilt its startTime from the stale creation time, so the animation immediately finished again. Check the finished state first in play(), and offset startTime by the animation duration when replaying in reverse so speed: -1 plays backwards. Thread the playback speed through getFinalKeyframe so animations that finish while reversed commit their first keyframe, including the WAAPI (AcceleratedAnimation) and mini (NativeAnimation) paths. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
🦋 Changeset detectedLatest commit: 6d356be The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
|
Warning Review limit reached
Next review available in: 47 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (9)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
commit: |
Ports three targeted behavioural fixes from upstream Motion (originally landed as part of the large "Animation refactor" in motiondivision/motion#3148) without the architectural rewrite. Upstream issues: #3133, #2947, #3113.
The three fixes interlock through
getFinalKeyframe, so they are delivered together.#3133 — a finished
MainThreadAnimationcould not be replayedteardown()nullsstartTimewhen an animation finishes, so onplay()the!this.startTimebranch fired first and rebuiltstartTimefrom the original, now-stalecreatedAt. The animation was therefore instantly "already finished" again, and thestate === 'finished'branch was unreachable.play()now checks the finished state first (matching upstreamJSAnimation.play()), rebasingstartTimeon the driver's current time.#2947 —
speed: -1did not play in reversegetFinalKeyframegained aspeedparameter and selects the first keyframe whenspeed < 0.play()offsetsstartTimebycalculatedDurationwhen replaying a finished animation in reverse.speedsetter now bringscurrentTimeup to date (updateTime(time.now())) before the new speed is applied, so elapsed time isn't rebased at the new speed. The current-time calculation was extracted fromtick()into a privateupdateTime()for this.#3113 — non-default
speedcommitted the wrong terminal keyframeAccelerated values such as
opacityrun on WAAPI, and the WAAPIonfinishhandlers committedgetFinalKeyframe(...)without a speed, so a reversed or sped-up animation snapped to the wrong end. Speed is now threaded through bothAcceleratedAnimationand the miniNativeAnimationpath.Note: upstream additionally clears
finishedTimewhen speed goes negative (NativeAnimation.ts). This port has nofinishedTimefield — itsstatereadsanimation.playStatedirectly — so there is no equivalent to port; introducing one belongs with the architectural rewrite.Tests
MainThreadAnimation: replaying a finished animation once the clock has moved on, and replaying it in reverse withspeed = -1. Both use a newpersistentSyncDrivertest helper whose clock survives driver teardown, mirroring the real frameloop driver (the existingsyncDriverresets to 0 on every driver instance, which masked the bug).getFinalKeyframe: first keyframe for negative speeds, final keyframe for positive speeds.AcceleratedAnimation: a WAAPI animation finishing in reverse commits the first keyframe; finishing atspeed = 2still commits the final keyframe.All four new tests fail on
mainand pass with this change. Full suite:bun run test:run— the only failures are pre-existing timeouts (package-imports,reorder-production-ssr) that pass in isolation on this machine and are unrelated to these changes.No architectural refactor, no unrelated changes.