Avoid moving RawProps during animation backend commit when retries are possible (#56465)

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

The `cloneProps` function in `AnimationBackend.cpp` was using `std::move(*animatedProps.rawProps)` inside a `shadowTree.commit()` transaction lambda. Since commits can be retried (when `currentRevision_.number != oldRevision.number`), the moved-from `RawProps` would be in an unspecified state on the second attempt, leading to incorrect or undefined behavior.

When `enableFabricCommitBranching` is enabled, commit retries are not a concern, so moving is safe. When disabled, we now copy via `RawProps(*animatedProps.rawProps)` instead.

This is the only dangerous move in the animation backend commit path. The `AnimationBackendCommitHook` already copies correctly (`RawProps(*snapshot->rawProps)`), and `AnimatedPropsRegistry::getMap()` is safe because moved pending data persists in the `map` member across retries.

Changelog: [General][Fixed] - Fix potential data corruption in animation backend when ShadowTree commits are retried by copying RawProps instead of moving them

Reviewed By: zeyap

Differential Revision: D101161363

fbshipit-source-id: 43b9277f37563098c8ba878777d7a3099bdf1373
This commit is contained in:
Bartlomiej Bloniarz authored and Alan Hughes committed 2026-04-20 12:41:01 +01:00
1 parent 16e6e32944
commit 430da64dc9
1 file changed
+11 -4
@@ -24,10 +24,17 @@ static inline Props::Shared cloneProps(
shadowNode.getSurfaceId(), *shadowNode.getContextContainer()};
Props::Shared newProps;
if (animatedProps.rawProps) {
newProps = shadowNode.getComponentDescriptor().cloneProps(
propsParserContext,
shadowNode.getProps(),
std::move(*animatedProps.rawProps));
if (ReactNativeFeatureFlags::enableFabricCommitBranching()) {
newProps = shadowNode.getComponentDescriptor().cloneProps(
propsParserContext,
shadowNode.getProps(),
std::move(*animatedProps.rawProps));
} else {
newProps = shadowNode.getComponentDescriptor().cloneProps(
propsParserContext,
shadowNode.getProps(),
RawProps(*animatedProps.rawProps));
}
} else {
newProps = shadowNode.getComponentDescriptor().cloneProps(
propsParserContext, shadowNode.getProps(), {});