Skip to content

Commit e04db8a

Browse files
javachefacebook-github-bot
authored andcommitted
Rollout useNativeState (#40864)
Summary: Changelog: [Internal] Use JSI's NativeState abstraction to reference C++ objects across JS calls Reviewed By: rubennorte, sammy-SC Differential Revision: D50176083
1 parent 3d5324a commit e04db8a

File tree

8 files changed

+18
-84
lines changed

8 files changed

+18
-84
lines changed

packages/react-native/React/Fabric/RCTSurfacePresenter.mm

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,6 @@ - (RCTScheduler *)_createScheduler
264264
CoreFeatures::enablePropIteratorSetter = true;
265265
}
266266

267-
if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:use_native_state")) {
268-
CoreFeatures::useNativeState = true;
269-
}
270-
271267
if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:cancel_image_downloads_on_recycle")) {
272268
CoreFeatures::cancelImageDownloadsOnRecycle = true;
273269
}

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,12 +129,6 @@ public class ReactFeatureFlags {
129129
*/
130130
public static boolean reduceDeleteCreateMutation = false;
131131

132-
/**
133-
* Use JSI NativeState API to store references to native objects rather than the more expensive
134-
* HostObject pattern
135-
*/
136-
public static boolean useNativeState = false;
137-
138132
/** Report mount operations from the host platform to notify mount hooks. */
139133
public static boolean enableMountHooks = false;
140134

packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,6 @@ void Binding::installFabricUIManager(
414414

415415
CoreFeatures::enablePropIteratorSetter =
416416
getFeatureFlagValue("enableCppPropsIteratorSetter");
417-
CoreFeatures::useNativeState = getFeatureFlagValue("useNativeState");
418417
CoreFeatures::doNotSwapLeftAndRightOnAndroidInLTR =
419418
getFeatureFlagValue("doNotSwapLeftAndRightOnAndroidInLTR");
420419
CoreFeatures::enableCleanParagraphYogaNode =

packages/react-native/ReactCommon/react/renderer/runtimescheduler/primitives.h

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,23 +13,12 @@
1313

1414
namespace facebook::react {
1515

16-
struct TaskWrapper : public jsi::HostObject {
17-
TaskWrapper(const std::shared_ptr<Task>& task) : task(task) {}
18-
19-
std::shared_ptr<Task> task;
20-
};
21-
2216
inline static jsi::Value valueFromTask(
2317
jsi::Runtime& runtime,
2418
std::shared_ptr<Task> task) {
25-
if (CoreFeatures::useNativeState) {
26-
jsi::Object obj(runtime);
27-
obj.setNativeState(runtime, std::move(task));
28-
return obj;
29-
} else {
30-
return jsi::Object::createFromHostObject(
31-
runtime, std::make_shared<TaskWrapper>(task));
32-
}
19+
jsi::Object obj(runtime);
20+
obj.setNativeState(runtime, std::move(task));
21+
return obj;
3322
}
3423

3524
inline static std::shared_ptr<Task> taskFromValue(
@@ -38,12 +27,7 @@ inline static std::shared_ptr<Task> taskFromValue(
3827
if (value.isNull()) {
3928
return nullptr;
4029
}
41-
42-
if (CoreFeatures::useNativeState) {
43-
return value.getObject(runtime).getNativeState<Task>(runtime);
44-
} else {
45-
return value.getObject(runtime).getHostObject<TaskWrapper>(runtime)->task;
46-
}
30+
return value.getObject(runtime).getNativeState<Task>(runtime);
4731
}
4832

4933
} // namespace facebook::react

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ namespace facebook::react {
3737
// "key function" for the ShadowNodeWrapper class -- this allow for RTTI to work
3838
// properly across dynamic library boundaries (i.e. dynamic_cast that is used by
3939
// isHostObject method)
40-
ShadowNodeWrapper::~ShadowNodeWrapper() = default;
4140
ShadowNodeListWrapper::~ShadowNodeListWrapper() = default;
4241

4342
static std::unique_ptr<LeakChecker> constructLeakCheckerIfNeeded(

packages/react-native/ReactCommon/react/renderer/uimanager/primitives.h

Lines changed: 14 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include <react/renderer/core/ShadowNode.h>
1818
#include <react/renderer/core/TraitCast.h>
1919
#include <react/renderer/graphics/Rect.h>
20-
#include <react/utils/CoreFeatures.h>
2120

2221
namespace facebook::react {
2322

@@ -31,19 +30,7 @@ struct EventHandlerWrapper : public EventHandler {
3130
jsi::Function callback;
3231
};
3332

34-
struct ShadowNodeWrapper : public jsi::HostObject {
35-
ShadowNodeWrapper(ShadowNode::Shared shadowNode)
36-
: shadowNode(std::move(shadowNode)) {}
37-
38-
// The below method needs to be implemented out-of-line in order for the class
39-
// to have at least one "key function" (see
40-
// https://itanium-cxx-abi.github.io/cxx-abi/abi.html#vague-vtable)
41-
~ShadowNodeWrapper() override;
42-
43-
ShadowNode::Shared shadowNode;
44-
};
45-
46-
struct ShadowNodeListWrapper : public jsi::HostObject, public jsi::NativeState {
33+
struct ShadowNodeListWrapper : public jsi::NativeState {
4734
ShadowNodeListWrapper(ShadowNode::UnsharedListOfShared shadowNodeList)
4835
: shadowNodeList(std::move(shadowNodeList)) {}
4936

@@ -62,28 +49,17 @@ inline static ShadowNode::Shared shadowNodeFromValue(
6249
return nullptr;
6350
}
6451

65-
if (CoreFeatures::useNativeState) {
66-
return value.getObject(runtime).getNativeState<ShadowNode>(runtime);
67-
} else {
68-
return value.getObject(runtime)
69-
.getHostObject<ShadowNodeWrapper>(runtime)
70-
->shadowNode;
71-
}
52+
return value.getObject(runtime).getNativeState<ShadowNode>(runtime);
7253
}
7354

7455
inline static jsi::Value valueFromShadowNode(
7556
jsi::Runtime& runtime,
7657
ShadowNode::Shared shadowNode) {
77-
if (CoreFeatures::useNativeState) {
78-
jsi::Object obj(runtime);
79-
// Need to const_cast since JSI only allows non-const pointees
80-
obj.setNativeState(
81-
runtime, std::const_pointer_cast<ShadowNode>(std::move(shadowNode)));
82-
return obj;
83-
} else {
84-
return jsi::Object::createFromHostObject(
85-
runtime, std::make_shared<ShadowNodeWrapper>(std::move(shadowNode)));
86-
}
58+
jsi::Object obj(runtime);
59+
// Need to const_cast since JSI only allows non-const pointees
60+
obj.setNativeState(
61+
runtime, std::const_pointer_cast<ShadowNode>(std::move(shadowNode)));
62+
return obj;
8763
}
8864

8965
// TODO: once we no longer need to mutate the return value (appendChildToSet)
@@ -112,13 +88,8 @@ inline static ShadowNode::UnsharedListOfShared shadowNodeListFromValue(
11288
;
11389
}
11490
} else {
115-
if (CoreFeatures::useNativeState) {
116-
return object.getNativeState<ShadowNodeListWrapper>(runtime)
117-
->shadowNodeList;
118-
} else {
119-
return object.getHostObject<ShadowNodeListWrapper>(runtime)
120-
->shadowNodeList;
121-
}
91+
return object.getNativeState<ShadowNodeListWrapper>(runtime)
92+
->shadowNodeList;
12293
}
12394
}
12495

@@ -127,15 +98,11 @@ inline static jsi::Value valueFromShadowNodeList(
12798
ShadowNode::UnsharedListOfShared shadowNodeList) {
12899
auto wrapper =
129100
std::make_shared<ShadowNodeListWrapper>(std::move(shadowNodeList));
130-
if (CoreFeatures::useNativeState) {
131-
// Use the wrapper for NativeState too, otherwise we can't implement
132-
// the marker interface. Could be simplified to a simple struct wrapper.
133-
jsi::Object obj(runtime);
134-
obj.setNativeState(runtime, std::move(wrapper));
135-
return obj;
136-
} else {
137-
return jsi::Object::createFromHostObject(runtime, std::move(wrapper));
138-
}
101+
// Use the wrapper for NativeState too, otherwise we can't implement
102+
// the marker interface. Could be simplified to a simple struct wrapper.
103+
jsi::Object obj(runtime);
104+
obj.setNativeState(runtime, std::move(wrapper));
105+
return obj;
139106
}
140107

141108
inline static ShadowNode::UnsharedListOfShared shadowNodeListFromWeakList(

packages/react-native/ReactCommon/react/utils/CoreFeatures.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ namespace facebook::react {
1111

1212
bool CoreFeatures::enablePropIteratorSetter = false;
1313
bool CoreFeatures::blockPaintForUseLayoutEffect = false;
14-
bool CoreFeatures::useNativeState = false;
1514
bool CoreFeatures::cacheLastTextMeasurement = false;
1615
bool CoreFeatures::cancelImageDownloadsOnRecycle = false;
1716
bool CoreFeatures::enableGranularScrollViewStateUpdatesIOS = false;

packages/react-native/ReactCommon/react/utils/CoreFeatures.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,6 @@ class CoreFeatures {
2424
// when a transaction is mounted.
2525
static bool blockPaintForUseLayoutEffect;
2626

27-
// Whether to use Hermes' NativeState instead of HostObject
28-
// in simple data passing scenarios with JS
29-
static bool useNativeState;
30-
3127
// Yoga might measure multiple times the same Text with the same constraints
3228
// This flag enables a caching mechanism to avoid subsequents measurements
3329
// of the same Text with the same constrainst.

0 commit comments

Comments
 (0)