Skip to content

Commit 5976273

Browse files
javachemeta-codesync[bot]
authored andcommitted
Move shadow-node ref update thread tag to Fabric install (#57497)
Summary: Pull Request resolved: #57497 The runtime shadow-node reference update thread tag was being set on every `RuntimeExecutor` tick in `ReactInstance`. Because the underlying flag is `thread_local` and only meaningful on the JS runtime thread, it's enough to set it once during Fabric installation. Move the `ShadowNode::setUseRuntimeShadowNodeReferenceUpdateOnThread` call into `UIManagerBinding::createAndInstallIfNeeded`, which runs on the JS thread and is guarded to execute once per runtime. This lets the `runtime` module drop its direct dependency on `renderer/core`, reducing coupling between the Bridgeless runtime host and the Fabric renderer. Behavior is unchanged: the write was already unconditional; the read at `updateMountedFlag` is still gated by the existing feature flag. Changelog: [Internal] Reviewed By: lenaic, zeyap Differential Revision: D111059967 fbshipit-source-id: e38a16f75ba972c214cd92637caf0441ee6a734e
1 parent d70113f commit 5976273

2 files changed

Lines changed: 7 additions & 2 deletions

File tree

packages/react-native/ReactCommon/react/renderer/uimanager/UIManagerBinding.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <react/debug/react_native_assert.h>
1414
#include <react/renderer/components/view/PointerEvent.h>
1515
#include <react/renderer/core/LayoutableShadowNode.h>
16+
#include <react/renderer/core/ShadowNode.h>
1617
#include <react/renderer/dom/DOM.h>
1718
#include <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h>
1819
#include <react/renderer/uimanager/primitives.h>
@@ -35,6 +36,12 @@ void UIManagerBinding::createAndInstallIfNeeded(
3536
auto object = jsi::Object::createFromHostObject(runtime, uiManagerBinding);
3637
runtime.global().setProperty(
3738
runtime, uiManagerModuleName, std::move(object));
39+
40+
// Tag this thread (the JS runtime thread) as the one allowed to propagate
41+
// runtime shadow-node reference updates during Fabric commit. The flag is
42+
// thread_local, so it must be set on the JS thread; installing the binding
43+
// is guaranteed to run there and to happen before any JS-driven commit.
44+
ShadowNode::setUseRuntimeShadowNodeReferenceUpdateOnThread(true);
3845
}
3946
}
4047

packages/react-native/ReactCommon/react/runtime/ReactInstance.cpp

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
#include <jsi/instrumentation.h>
1919
#include <jsinspector-modern/HostTarget.h>
2020
#include <react/featureflags/ReactNativeFeatureFlags.h>
21-
#include <react/renderer/core/ShadowNode.h>
2221
#include <react/renderer/runtimescheduler/RuntimeSchedulerBinding.h>
2322
#include <react/runtime/JSRuntimeBindings.h>
2423
#include <react/timing/primitives.h>
@@ -98,7 +97,6 @@ ReactInstance::ReactInstance(
9897
jsi::Runtime& jsiRuntime = runtime->getRuntime();
9998
TraceSection s("ReactInstance::_runtimeExecutor[Callback]");
10099
try {
101-
ShadowNode::setUseRuntimeShadowNodeReferenceUpdateOnThread(true);
102100
callback(jsiRuntime);
103101
} catch (jsi::JSError& originalError) {
104102
jsErrorHandler->handleError(jsiRuntime, originalError, true);

0 commit comments

Comments
 (0)