Skip to content

Fix animation race condition for dynamic fillValue updates#144

Merged
jkhusanov merged 8 commits intoanimation-fixfrom
copilot/sub-pr-141-again
Feb 23, 2026
Merged

Fix animation race condition for dynamic fillValue updates#144
jkhusanov merged 8 commits intoanimation-fixfrom
copilot/sub-pr-141-again

Conversation

Copy link
Contributor

Copilot AI commented Feb 18, 2026

Dynamic fillValue updates during an in-flight animation are dropped. The effect re-runs but exits early via animationRunning.current, and refs don't trigger rerenders when the animation completes.

Changes

Core fix:

  • Replace boolean animationRunning ref with currentAnimation ref storing the animation object
  • Cancel in-flight animations via .stop() when new fillValue arrives
  • Start new animation immediately with latest value

Animation lifecycle:

  • Callback clears reference only when currentAnimation.current === animation && finished
  • Prevents stopped animations (finished: false) from clearing active animation
  • Cleanup function stops animation if still current and clears reference

Dependencies:

  • Remove arcAnimatedValue from dependency array (stable across renders)
  • Keep lastFilledSegment.filled to trigger on value changes only

Tests:

  • Add mock stop method to animation objects
  • Verify stopped animation callbacks don't interfere with new animations
  • Extract reusable animation mock helper
// Before: updates dropped during animation
useEffect(() => {
  if (animationRunning.current) return;  // Exits, never retries
  animationRunning.current = true;
  Animated.timing(...).start(() => animationRunning.current = false);
}, [lastFilledSegment.filled]);

// After: in-flight animations cancelled
useEffect(() => {
  if (currentAnimation.current) currentAnimation.current.stop();
  
  const animation = Animated.timing(...);
  currentAnimation.current = animation;
  animation.start(({ finished }) => {
    if (currentAnimation.current === animation && finished) {
      currentAnimation.current = null;
    }
  });
  
  return () => {
    if (currentAnimation.current === animation) {
      animation.stop();
      currentAnimation.current = null;
    }
  };
}, [lastFilledSegment.filled, animationDuration, animationDelay, isAnimated]);

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 7 commits February 18, 2026 20:41
Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>
Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>
Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>
Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>
Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>
Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>
Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>
Copilot AI changed the title [WIP] Update animation fix for dynamic fillValue based on feedback Fix animation race condition for dynamic fillValue updates Feb 18, 2026
Copilot AI requested a review from jkhusanov February 18, 2026 20:52
@jkhusanov jkhusanov marked this pull request as ready for review February 23, 2026 19:12
@jkhusanov jkhusanov merged commit a21a943 into animation-fix Feb 23, 2026
1 check passed
@jkhusanov jkhusanov deleted the copilot/sub-pr-141-again branch February 23, 2026 19:12
jkhusanov added a commit that referenced this pull request Feb 25, 2026
* Support dynamic fill value

* Fix segments animation when going back

* Fix animation race condition for dynamic fillValue updates (#144)

* Initial plan

* Fix animation race condition by cancelling in-flight animations

Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>

* Add test for animation cancellation during updates

Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>

* Properly handle animation reference cleanup after cancellation

Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>

* Improve animation cleanup logic to prevent race conditions

Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>

* Refine animation cleanup to prevent race conditions

Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>

* Address final code review feedback

Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>

* Clear animation reference in cleanup and improve test helper reusability

Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>

---------

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: jkhusanov <25942541+jkhusanov@users.noreply.github.com>

---------

Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>
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