Skip to content

Commit 1156c08

Browse files
Nick Lefeverfacebook-github-bot
authored andcommitted
Move shadow node reference updates to tree commit (facebook#50753)
Summary: Pull Request resolved: facebook#50753 Runtime Shadow Node Reference Updates (RSNRU) is currently implemented through the clone method which on each internal clone updates the runtime reference to point to the new clone. This guarantees that the runtime reference always points at the latest revision of the shadow node. This came with the constraint that RSNRU could only run from one thread at all times, otherwise the React renderer state (current fiber tree) would end up being corrupted by receiving reference updates from multiple threads cloning shadow nodes. This change moves the reference update step to the locked scope of the commit phase. Since the runtime is blocking on the commit and the scope is locked, it is safe and correct to update the runtime references with the latest revision of the shadow node after running state progression and layout. By moving the reference update to the commit, we can support shadow node syncing from any thread since the actual runtime references are now executing at a safe time and the renderer state will stay valid at all times. This change is gated behind the `updateRuntimeShadowNodeReferencesOnCommit` feature flag, which enabled shadow node syncing from any thread and reference updates only during the commit. Changelog: [Internal] Reviewed By: rubennorte Differential Revision: D73038439 fbshipit-source-id: d90308498f3c0625dc87158f15311d1088aad8b0
1 parent 2080fd8 commit 1156c08

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,13 +322,16 @@ void ShadowNode::transferRuntimeShadowNodeReference(
322322
destinationShadowNode->runtimeShadowNodeReference_ =
323323
runtimeShadowNodeReference_;
324324

325-
updateRuntimeShadowNodeReference(destinationShadowNode);
325+
if (!ReactNativeFeatureFlags::updateRuntimeShadowNodeReferencesOnCommit()) {
326+
updateRuntimeShadowNodeReference(destinationShadowNode);
327+
}
326328
}
327329

328330
void ShadowNode::transferRuntimeShadowNodeReference(
329331
const Shared& destinationShadowNode,
330332
const ShadowNodeFragment& fragment) const {
331-
if (useRuntimeShadowNodeReferenceUpdateOnThread &&
333+
if ((ReactNativeFeatureFlags::updateRuntimeShadowNodeReferencesOnCommit() ||
334+
useRuntimeShadowNodeReferenceUpdateOnThread) &&
332335
fragment.runtimeShadowNodeReference) {
333336
transferRuntimeShadowNodeReference(destinationShadowNode);
334337
}

packages/react-native/ReactCommon/react/renderer/mounting/updateMountedFlag.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77

88
#include "updateMountedFlag.h"
99

10+
#include <react/featureflags/ReactNativeFeatureFlags.h>
11+
1012
namespace facebook::react {
1113
void updateMountedFlag(
1214
const ShadowNode::ListOfShared& oldChildren,
@@ -47,6 +49,10 @@ void updateMountedFlag(
4749
newChild->setMounted(true);
4850
oldChild->setMounted(false);
4951

52+
if (ReactNativeFeatureFlags::updateRuntimeShadowNodeReferencesOnCommit()) {
53+
newChild->updateRuntimeShadowNodeReference(newChild);
54+
}
55+
5056
updateMountedFlag(oldChild->getChildren(), newChild->getChildren());
5157
}
5258

0 commit comments

Comments
 (0)