Skip to content

Fix crash in tracking spring animations when toValue node is detached#55734

Open
kmsbernard wants to merge 2 commits intofacebook:mainfrom
kmsbernard:fix/android-tracking-spring-null-tovalue-crash
Open

Fix crash in tracking spring animations when toValue node is detached#55734
kmsbernard wants to merge 2 commits intofacebook:mainfrom
kmsbernard:fix/android-tracking-spring-null-tovalue-crash

Conversation

@kmsbernard
Copy link
Contributor

@kmsbernard kmsbernard commented Feb 25, 2026

Summary:

This PR fixes an Android Native Animated crash in tracking + spring animations when the tracked toValue node is detached.

In TrackingAnimatedNode.update, if the tracked node could not be resolved, we used to write toValue = null into animationConfig. SpringAnimation.resetConfig expects toValue to be a number, so this could crash with NullPointerException: null cannot be cast to non-null type kotlin.Number

This can happen in real apps during graph teardown (for example unmount/re-render/navigation transitions), where tracking may still update for a transient frame after the tracked node has been detached.

Fix:

  • Do not propagate null toValue from TrackingAnimatedNode.
  • If the tracked node is missing, fallback to the driven value node’s current value.
  • If both nodes are unavailable, return safely.

This PR also adds a regression test.

Changelog:

[ANDROID] [FIXED] - Prevent Native Animated tracking spring crash when tracked toValue node is detached.

Test Plan:

Added regression test NativeAnimatedNodeTraversalTest.testTrackingSpringDoesNotCrashWhenToValueNodeIsDetached

  • On a test-only commit (without the fix), the new test fails with: NullPointerException: null cannot be cast to non-null type kotlin.Number
  • On this PR (with the fix), test pass.

@meta-cla meta-cla bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Feb 25, 2026
@facebook-github-bot facebook-github-bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Feb 25, 2026
@kmsbernard kmsbernard changed the title Fix tracking spring crash when toValue node is detached Fix crash in tracking spring animations when toValue node is detached Feb 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants