SIGN IN SIGN UP
facebook / react-native UNCLAIMED

A framework for building native applications using React

0 0 0 C++

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

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.

Pull Request resolved: https://github.com/facebook/react-native/pull/55734

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.

Reviewed By: christophpurrer

Differential Revision: D94697059

Pulled By: zeyap

fbshipit-source-id: c8f1f619c34ce7887d6f9bfb42a035d41d6a063a
M
Minsik Kim committed
45de7109fe93db8052e9ba06e53807f89cbd7fd9
Parent: ee5b089
Committed by meta-codesync[bot] <215208954+meta-codesync[bot]@users.noreply.github.com> on 2/27/2026, 9:35:00 PM