Skip to content

Commit fd57e39

Browse files
javachefacebook-github-bot
authored andcommitted
Skip initial yogaLayoutableChildren_ build when fragment.children is set (#57020)
Summary: On the `fragment.children` path, the clone constructor used to iterate every child with `dynamic_pointer_cast` only to have `updateYogaChildren()` clear and rebuild the same vector a few lines later. Drop the initial loop — `updateYogaChildren()` is the single source of truth on this path. `updateYogaChildrenOwnersIfNeeded()` runs in between but iterates `yogaNode_.getChildren()` (inherited from the source's Yoga node copy) rather than `yogaLayoutableChildren_`, so leaving the vector empty here is safe. Changelog: [Internal] Reviewed By: lenaic, christophpurrer Differential Revision: D107076026
1 parent 676ff8f commit fd57e39

1 file changed

Lines changed: 9 additions & 16 deletions

File tree

packages/react-native/ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp

Lines changed: 9 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -113,22 +113,15 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode(
113113
.yogaNode_) == YGNodeIsDirty(&yogaNode_) &&
114114
"Yoga node must inherit dirty flag.");
115115
#endif
116-
if (!getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) {
117-
if (!fragment.children) {
118-
// Children unchanged - copy the filtered list directly from the source
119-
// node, avoiding expensive dynamic_pointer_cast on every child.
120-
yogaLayoutableChildren_ =
121-
static_cast<const YogaLayoutableShadowNode&>(sourceShadowNode)
122-
.yogaLayoutableChildren_;
123-
} else {
124-
for (auto& child : getChildren()) {
125-
if (auto layoutableChild =
126-
std::dynamic_pointer_cast<const YogaLayoutableShadowNode>(
127-
child)) {
128-
yogaLayoutableChildren_.push_back(std::move(layoutableChild));
129-
}
130-
}
131-
}
116+
if (!getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode) &&
117+
!fragment.children) {
118+
// Children unchanged: copy the filtered list directly from the source,
119+
// skipping per-child dynamic_pointer_cast. When fragment.children is set,
120+
// updateYogaChildren() below rebuilds the vector from the new children
121+
// list — populating it here would be immediately discarded.
122+
yogaLayoutableChildren_ =
123+
static_cast<const YogaLayoutableShadowNode&>(sourceShadowNode)
124+
.yogaLayoutableChildren_;
132125
}
133126

134127
YGConfigConstRef previousConfig =

0 commit comments

Comments
 (0)