From 85696298bf36203c94d586cf95f74e71a3c9d5d4 Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Fri, 28 Feb 2020 06:14:33 -0800 Subject: [PATCH] Fix yoga node owner getting out of sync with children Summary: Changelog: [internal] # Problem We have node A with N children. Calling cloning constructor on `YogaLayoutableShadowNode` causes new `yogaNode_` to be created. However if `fragment.children` is nil in cloning constructor, which basically says children were not changed, then the existing children's `owner` becomes invalid. # Solution In the clone constructor, always call `updateYogaChildren`. This updates yoga children with the new `owner`. Reviewed By: JoshuaGross Differential Revision: D20139582 fbshipit-source-id: 3932694d4381b601df07dd8a57887ce7c09f1582 --- .../components/view/yoga/YogaLayoutableShadowNode.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp index d05df322291..f4bd3ca6ddd 100644 --- a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp +++ b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp @@ -61,9 +61,10 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode( updateYogaProps(); } - if (fragment.children) { - updateYogaChildren(); - } + // Yoga children have `yogaNode_` set as owner. At this point that yogaNode_ + // is from previous `YogaLayoutableShadowNode` that is being cloned here. + // Calling `updateYogaChildren` is needed in order to update owner of children. + updateYogaChildren(); } void YogaLayoutableShadowNode::cleanLayout() {