diff --git a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp index 9e15d72e04..1a9982b2cf 100644 --- a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp +++ b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.cpp @@ -73,6 +73,7 @@ YogaLayoutableShadowNode::YogaLayoutableShadowNode( &initializeYogaConfig(yogaConfig_)) { yogaNode_.setContext(this); yogaNode_.setOwner(nullptr); + updateYogaChildrenOwnersIfNeeded(); // Yoga node must inherit dirty flag. assert( @@ -223,6 +224,14 @@ bool YogaLayoutableShadowNode::doesOwn( return child.yogaNode_.getOwner() == &yogaNode_; } +void YogaLayoutableShadowNode::updateYogaChildrenOwnersIfNeeded() { + for (auto &childYogaNode : yogaNode_.getChildren()) { + if (childYogaNode->getOwner() == &yogaNode_) { + childYogaNode->setOwner(reinterpret_cast(0xBADC0FFEE0DDF00D)); + } + } +} + void YogaLayoutableShadowNode::updateYogaChildren() { if (getTraits().check(ShadowNodeTraits::Trait::LeafYogaNode)) { return; diff --git a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h index e9ea29cd47..59148e333b 100644 --- a/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h +++ b/ReactCommon/fabric/components/view/yoga/YogaLayoutableShadowNode.h @@ -100,6 +100,16 @@ class YogaLayoutableShadowNode : public LayoutableShadowNode { mutable YGNode yogaNode_; private: + /* + * Goes over `yogaNode_.getChildren()` and in case child's owner is + * equal to address of `yogaNode_`, it sets child's owner address + * to `0xBADC0FFEE0DDF00D`. This is magic constant, the intention + * is to make debugging easier when the address pops up in debugger. + * This prevents ABA problem where child yoga node goes from owned -> unowned + * -> back to owned because its parent is allocated at the same address. + */ + void updateYogaChildrenOwnersIfNeeded(); + /* * Return true if child's yogaNode's owner is this->yogaNode_. Otherwise * returns false.