Skip to content

Commit 8c86da6

Browse files
Guard C++ TransformAnimatedNode against static transforms without a numeric value
Summary: `TransformAnimatedNode::collectViewUpdates` read a static transform's value with a const `folly::dynamic` `operator[]` followed by `asDouble()`. When a JS transform entry is `undefined` (e.g. `transform: [{translateX: anim}, {scale: undefined}]`), `AnimatedTransform.__getNativeConfig` emits `{type: 'static', property, value: undefined}`, and the JSI-to-dynamic conversion drops undefined properties, so the `value` key is missing. The lookup throws `std::out_of_range`, which escapes the `noexcept` `NativeAnimatedNodesManager::connectAnimatedNodeToView` / `updateNodes` callers and calls `std::terminate`. A `null` or non-numeric value threw `folly::TypeError` the same way. Skip static entries whose value is missing or not a number, as already happens when an animated entry's input node is absent. Changelog: [General][Fixed] - Fix crash in the C++ native animated backend when a transform with a native-driven value also contains an `undefined` or non-numeric static entry Differential Revision: D132012881 Pull Request resolved: #60093
1 parent 13b3b85 commit 8c86da6

2 files changed

Lines changed: 57 additions & 2 deletions

File tree

‎packages/react-native/ReactCommon/react/renderer/animated/nodes/TransformAnimatedNode.cpp‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,11 @@ void TransformAnimatedNode::collectViewUpdates(folly::dynamic& props) {
4444
manager_->getAnimatedNode<ValueAnimatedNode>(inputTag)) {
4545
value = node->getValue();
4646
}
47-
} else {
48-
value = transform[sValueName].asDouble();
47+
} else if (const auto* staticValue = transform.get_ptr(sValueName);
48+
staticValue != nullptr && staticValue->isNumber()) {
49+
// JS omits the key when the static value is `undefined`; throwing here
50+
// would escape the noexcept callers and abort the app.
51+
value = staticValue->asDouble();
4952
}
5053
if (value) {
5154
const auto property = transform[sPropertyName].asString();

‎packages/react-native/ReactCommon/react/renderer/animated/tests/AnimatedNodeTests.cpp‎

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,58 @@ TEST_F(AnimatedNodeTests, ObjectAnimatedNode) {
413413
EXPECT_EQ(collectedProps["test"][2]["scale3d"], 4);
414414
}
415415

416+
TEST_F(AnimatedNodeTests, TransformNodeSkipsStaticEntryWithoutNumericValue) {
417+
initNodesManager();
418+
419+
auto rootTag = getNextRootViewTag();
420+
auto valueTag = ++rootTag;
421+
nodesManager_->createAnimatedNode(
422+
valueTag,
423+
folly::dynamic::object("type", "value")("value", 10)("offset", 0));
424+
425+
// A static transform whose JS value was `undefined` arrives with no "value"
426+
// key, and a `null` value arrives as null.
427+
auto transformTag = ++rootTag;
428+
nodesManager_->createAnimatedNode(
429+
transformTag,
430+
folly::dynamic::object("type", "transform")(
431+
"transforms",
432+
folly::dynamic::array(
433+
folly::dynamic::object("type", "animated")(
434+
"property", "translateX")("nodeTag", valueTag),
435+
folly::dynamic::object("type", "static")("property", "scale"),
436+
folly::dynamic::object("type", "static")("property", "rotate")(
437+
"value", nullptr),
438+
folly::dynamic::object("type", "static")(
439+
"property", "translateY")("value", 5))));
440+
nodesManager_->connectAnimatedNodes(valueTag, transformTag);
441+
442+
auto styleTag = ++rootTag;
443+
nodesManager_->createAnimatedNode(
444+
styleTag,
445+
folly::dynamic::object("type", "style")(
446+
"style", folly::dynamic::object("transform", transformTag)));
447+
nodesManager_->connectAnimatedNodes(transformTag, styleTag);
448+
449+
auto propsTag = ++rootTag;
450+
nodesManager_->createAnimatedNode(
451+
propsTag,
452+
folly::dynamic::object("type", "props")(
453+
"props", folly::dynamic::object("style", styleTag)));
454+
nodesManager_->connectAnimatedNodes(styleTag, propsTag);
455+
456+
auto viewTag = ++rootTag;
457+
nodesManager_->connectAnimatedNodeToView(propsTag, viewTag);
458+
459+
nodesManager_->setAnimatedNodeValue(valueTag, 20);
460+
runAnimationFrame(0);
461+
462+
const auto& transforms = lastCommittedProps["transform"];
463+
ASSERT_EQ(transforms.size(), 2u);
464+
EXPECT_EQ(transforms[0]["translateX"].asDouble(), 20);
465+
EXPECT_EQ(transforms[1]["translateY"].asDouble(), 5);
466+
}
467+
416468
// Styles that Animated supports and that do not participate in layout must be
417469
// direct-manipulation eligible; anything absent from this set is treated as a
418470
// layout update by StyleAnimatedNode and forced through a Fabric commit.

0 commit comments

Comments
 (0)