Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,8 @@ bool ShadowNode::progressStateIfNecessary() {
}

void ShadowNode::setRuntimeShadowNodeReference(
ShadowNodeWrapper* runtimeShadowNodeReference) const {
const std::shared_ptr<ShadowNodeWrapper>& runtimeShadowNodeReference)
const {
runtimeShadowNodeReference_ = runtimeShadowNodeReference;
}

Expand All @@ -319,8 +320,8 @@ void ShadowNode::transferRuntimeShadowNodeReference(
destinationShadowNode->runtimeShadowNodeReference_ =
runtimeShadowNodeReference_;

if (runtimeShadowNodeReference_ != nullptr) {
runtimeShadowNodeReference_->shadowNode = destinationShadowNode;
if (auto reference = runtimeShadowNodeReference_.lock()) {
reference->shadowNode = destinationShadowNode;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,11 @@ class ShadowNode : public Sealable,
bool progressStateIfNecessary();

/*
* Bind the runtime reference to this `ShadowNode` with a raw pointer,
* Bind the runtime reference to this `ShadowNode` with a weak pointer,
* allowing to update the reference to this `ShadowNode` when cloned.
*/
void setRuntimeShadowNodeReference(
ShadowNodeWrapper* runtimeShadowNodeReference) const;
void setRuntimeShadowNodeReference(const std::shared_ptr<ShadowNodeWrapper>&
runtimeShadowNodeReference) const;

/*
* Transfer the runtime reference to this `ShadowNode` to a new instance,
Expand Down Expand Up @@ -269,9 +269,9 @@ class ShadowNode : public Sealable,
ShadowNodeTraits traits_;

/*
* Pointer to the runtime reference to this `ShadowNode`.
* Weak pointer to the runtime reference to this `ShadowNode`.
*/
mutable ShadowNodeWrapper* runtimeShadowNodeReference_{};
mutable std::weak_ptr<ShadowNodeWrapper> runtimeShadowNodeReference_{};
};

static_assert(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ TEST_P(ShadowNodeTest, testCloneTree) {
TEST_P(ShadowNodeTest, handleRuntimeReferenceTransferOnClone) {
auto nodeABRev1 = nodeAB_->clone({});
auto wrappedShadowNode = std::make_shared<ShadowNodeWrapper>(nodeABRev1);
nodeABRev1->setRuntimeShadowNodeReference(&*wrappedShadowNode);
nodeABRev1->setRuntimeShadowNodeReference(wrappedShadowNode);

auto nodeABRev2 = nodeABRev1->clone({});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ inline static jsi::Value valueFromShadowNode(

if (assignRuntimeShadowNodeReference) {
wrappedShadowNode->shadowNode->setRuntimeShadowNodeReference(
&*wrappedShadowNode);
wrappedShadowNode);
}

jsi::Object obj(runtime);
Expand Down