Skip to content

Commit 15a795e

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Split shadow node reference setter and update functionality (facebook#50752)
Summary: Storing the runtime reference for a shadow node and updating the runtime reference to point at a specific shadow node should be separated so that these actions can be done at different moments in time. We want to keep a reference to the runtime reference of a shadow node for all revisions cloned internally (not triggered by the React renderer, e.g. on layout or shadow node state updates). We also want to support updating that runtime reference to point at a specific shadow node revision, ideally the one that will end up being used to mount the host component. Changelog: [Internal] Differential Revision: D73038438
1 parent d04397d commit 15a795e

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/react-native/ReactCommon/react/renderer/core/ShadowNode.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -308,14 +308,19 @@ void ShadowNode::setRuntimeShadowNodeReference(
308308
runtimeShadowNodeReference_ = runtimeShadowNodeReference;
309309
}
310310

311+
void ShadowNode::updateRuntimeShadowNodeReference(
312+
const Shared& destinationShadowNode) const {
313+
if (auto reference = runtimeShadowNodeReference_.lock()) {
314+
reference->shadowNode = destinationShadowNode;
315+
}
316+
}
317+
311318
void ShadowNode::transferRuntimeShadowNodeReference(
312319
const Shared& destinationShadowNode) const {
313320
destinationShadowNode->runtimeShadowNodeReference_ =
314321
runtimeShadowNodeReference_;
315322

316-
if (auto reference = runtimeShadowNodeReference_.lock()) {
317-
reference->shadowNode = destinationShadowNode;
318-
}
323+
updateRuntimeShadowNodeReference(destinationShadowNode);
319324
}
320325

321326
void ShadowNode::transferRuntimeShadowNodeReference(

packages/react-native/ReactCommon/react/renderer/core/ShadowNode.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,12 @@ class ShadowNode : public Sealable,
187187
void setRuntimeShadowNodeReference(const std::shared_ptr<ShadowNodeWrapper>&
188188
runtimeShadowNodeReference) const;
189189

190+
/*
191+
* Update the runtime reference to point to the provided shadow node.
192+
*/
193+
void updateRuntimeShadowNodeReference(
194+
const Shared& destinationShadowNode) const;
195+
190196
/*
191197
* Transfer the runtime reference to this `ShadowNode` to a new instance,
192198
* updating the reference to point to the new `ShadowNode` referencing it.

0 commit comments

Comments
 (0)