Skip to content

Commit 3af7d4a

Browse files
hannojgNick Lefever
authored andcommitted
new arch rn078 fixes (#62)
* Split shadow node reference setter and update functionality (facebook#50752) Summary: Pull Request resolved: facebook#50752 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] Reviewed By: rubennorte Differential Revision: D73038438 fbshipit-source-id: 68c3912cbb077d790dd8d2abe8291548b12c8231 * 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 * rename feature flag used mirroring: facebook@1156c08#diff-401e4af73546645a81c7e2c576b1319d0d819d92d0c214c88e3759bcb4d5e9c2R53-R54 * enable feature flag * rename feature flag used mirroring: facebook@1156c08#diff-401e4af73546645a81c7e2c576b1319d0d819d92d0c214c88e3759bcb4d5e9c2R53-R54 --------- Co-authored-by: Nick Lefever <lefever@meta.com> Co-authored-by: Hanno J. Gödecke <die.drei99@yahoo.de>
1 parent 0d785f4 commit 3af7d4a

File tree

4 files changed

+26
-2
lines changed

4 files changed

+26
-2
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/defaults/DefaultNewArchitectureEntryPoint.kt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ public object DefaultNewArchitectureEntryPoint {
5151
bridgelessEnabled || fabricEnabled
5252

5353
override fun useTurboModules(): Boolean = bridgelessEnabled || turboModulesEnabled
54+
55+
// Fixes reanimated flickering issues where shadow node updates on the UI thread wouldn't be
56+
// propagated back to the react JS fiber node/tree.
57+
override fun useRuntimeShadowNodeReferenceUpdate(): Boolean =
58+
bridgelessEnabled || turboModulesEnabled
5459
})
5560

5661
privateFabricEnabled = fabricEnabled

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -308,13 +308,20 @@ 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;
323+
if (!ReactNativeFeatureFlags::useRuntimeShadowNodeReferenceUpdate()) {
324+
updateRuntimeShadowNodeReference(destinationShadowNode);
318325
}
319326
}
320327

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.

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::useRuntimeShadowNodeReferenceUpdate()) {
53+
newChild->updateRuntimeShadowNodeReference(newChild);
54+
}
55+
5056
updateMountedFlag(oldChild->getChildren(), newChild->getChildren());
5157
}
5258

0 commit comments

Comments
 (0)