diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp index 04fb5d30f..e1394cccc 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.cpp +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.cpp @@ -68,7 +68,7 @@ InstanceHandle ShadowNode::getInstanceHandle() const { } SharedShadowNode ShadowNode::getSourceNode() const { - return sourceNode_; + return sourceNode_.lock(); } void ShadowNode::sealRecursive() const { @@ -111,7 +111,7 @@ void ShadowNode::replaceChild(const SharedShadowNode &oldChild, const SharedShad void ShadowNode::clearSourceNode() { ensureUnsealed(); - sourceNode_ = nullptr; + sourceNode_.reset(); } #pragma mark - DebugStringConvertible @@ -146,10 +146,11 @@ SharedDebugStringConvertibleList ShadowNode::getDebugProps() const { list.push_back(std::make_shared("handle", std::to_string((size_t)instanceHandle_))); } - if (sourceNode_) { + SharedShadowNode sourceNode = getSourceNode(); + if (sourceNode) { list.push_back(std::make_shared( "source", - sourceNode_->getDebugDescription({.maximumDepth = 1, .format = false}) + sourceNode->getDebugDescription({.maximumDepth = 1, .format = false}) )); } diff --git a/ReactCommon/fabric/core/shadownode/ShadowNode.h b/ReactCommon/fabric/core/shadownode/ShadowNode.h index 1deb4d520..aa68556f9 100644 --- a/ReactCommon/fabric/core/shadownode/ShadowNode.h +++ b/ReactCommon/fabric/core/shadownode/ShadowNode.h @@ -24,6 +24,7 @@ using SharedShadowNode = std::shared_ptr; using SharedShadowNodeList = std::vector>; using SharedShadowNodeSharedList = std::shared_ptr; using SharedShadowNodeUnsharedList = std::shared_ptr; +using WeakShadowNode = std::weak_ptr; class ShadowNode: public virtual Sealable, @@ -79,7 +80,7 @@ protected: InstanceHandle instanceHandle_; SharedProps props_; SharedShadowNodeSharedList children_; - SharedShadowNode sourceNode_; + WeakShadowNode sourceNode_; }; } // namespace react