Add feature flag for clone reference updates only on layout (#44771)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/44771

Changelog: [Internal]

Adding a feature flag for enabling runtime shadow node reference updates only for clones happening within `YogaLayoutableShadowNode` to support layout data changes.

Reviewed By: sammy-SC

Differential Revision: D58000072

fbshipit-source-id: 204c0488edb992511a4b33d098b9df1b04001b9d
This commit is contained in:
Nick Lefever
2024-06-03 20:25:46 -07:00
committed by Facebook GitHub Bot
parent a643e191f6
commit 4806077457
19 changed files with 122 additions and 20 deletions
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<987e450aa9db1b9da0e2a5a63deae4fe>>
* @generated SignedSource<<bc03d88b59af436b2db4f9048184a881>>
*/
/**
@@ -154,6 +154,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun useRuntimeShadowNodeReferenceUpdate(): Boolean = accessor.useRuntimeShadowNodeReferenceUpdate()
/**
* When enabled, cloning shadow nodes during layout will update the reference held by the current JS fiber tree.
*/
@JvmStatic
public fun useRuntimeShadowNodeReferenceUpdateOnLayout(): Boolean = accessor.useRuntimeShadowNodeReferenceUpdateOnLayout()
/**
* When enabled, it uses optimised state reconciliation algorithm.
*/
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<1a6f57f6bc5b8efd35d6846c71166126>>
* @generated SignedSource<<546c981f0b56bb022ad4e96e6a6ddb17>>
*/
/**
@@ -41,6 +41,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var useModernRuntimeSchedulerCache: Boolean? = null
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
private var useRuntimeShadowNodeReferenceUpdateCache: Boolean? = null
private var useRuntimeShadowNodeReferenceUpdateOnLayoutCache: Boolean? = null
private var useStateAlignmentMechanismCache: Boolean? = null
override fun commonTestFlag(): Boolean {
@@ -232,6 +233,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}
override fun useRuntimeShadowNodeReferenceUpdateOnLayout(): Boolean {
var cached = useRuntimeShadowNodeReferenceUpdateOnLayoutCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.useRuntimeShadowNodeReferenceUpdateOnLayout()
useRuntimeShadowNodeReferenceUpdateOnLayoutCache = cached
}
return cached
}
override fun useStateAlignmentMechanism(): Boolean {
var cached = useStateAlignmentMechanismCache
if (cached == null) {
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<1b8b3b8d140faefe9e5269b27770b235>>
* @generated SignedSource<<d3e722e1630002aee16eaf33b60c8a8f>>
*/
/**
@@ -70,6 +70,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
@DoNotStrip @JvmStatic public external fun useRuntimeShadowNodeReferenceUpdate(): Boolean
@DoNotStrip @JvmStatic public external fun useRuntimeShadowNodeReferenceUpdateOnLayout(): Boolean
@DoNotStrip @JvmStatic public external fun useStateAlignmentMechanism(): Boolean
@DoNotStrip @JvmStatic public external fun override(provider: Any)
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<656d5e2feea3ec122516b75eaacc3323>>
* @generated SignedSource<<8cb9343bf5aa9a7ec1940720ce253c5b>>
*/
/**
@@ -65,5 +65,7 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
override fun useRuntimeShadowNodeReferenceUpdate(): Boolean = false
override fun useRuntimeShadowNodeReferenceUpdateOnLayout(): Boolean = false
override fun useStateAlignmentMechanism(): Boolean = false
}
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<206771bdb2b95a893dd6a0dcba5dc48a>>
* @generated SignedSource<<3b6ad9b32518e319bb7d11da4eaa262c>>
*/
/**
@@ -45,6 +45,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var useModernRuntimeSchedulerCache: Boolean? = null
private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null
private var useRuntimeShadowNodeReferenceUpdateCache: Boolean? = null
private var useRuntimeShadowNodeReferenceUpdateOnLayoutCache: Boolean? = null
private var useStateAlignmentMechanismCache: Boolean? = null
override fun commonTestFlag(): Boolean {
@@ -257,6 +258,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}
override fun useRuntimeShadowNodeReferenceUpdateOnLayout(): Boolean {
var cached = useRuntimeShadowNodeReferenceUpdateOnLayoutCache
if (cached == null) {
cached = currentProvider.useRuntimeShadowNodeReferenceUpdateOnLayout()
accessedFeatureFlags.add("useRuntimeShadowNodeReferenceUpdateOnLayout")
useRuntimeShadowNodeReferenceUpdateOnLayoutCache = cached
}
return cached
}
override fun useStateAlignmentMechanism(): Boolean {
var cached = useStateAlignmentMechanismCache
if (cached == null) {
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<e59baa7b1764857cbd11a14853ad420a>>
* @generated SignedSource<<af167f52f81a78ac200159717eb55e8e>>
*/
/**
@@ -65,5 +65,7 @@ public interface ReactNativeFeatureFlagsProvider {
@DoNotStrip public fun useRuntimeShadowNodeReferenceUpdate(): Boolean
@DoNotStrip public fun useRuntimeShadowNodeReferenceUpdateOnLayout(): Boolean
@DoNotStrip public fun useStateAlignmentMechanism(): Boolean
}
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<ef2907316ba5f741430090aedd47212a>>
* @generated SignedSource<<43b256d5f58743df52f579dc69721083>>
*/
/**
@@ -165,6 +165,12 @@ class ReactNativeFeatureFlagsProviderHolder
return method(javaProvider_);
}
bool useRuntimeShadowNodeReferenceUpdateOnLayout() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useRuntimeShadowNodeReferenceUpdateOnLayout");
return method(javaProvider_);
}
bool useStateAlignmentMechanism() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("useStateAlignmentMechanism");
@@ -280,6 +286,11 @@ bool JReactNativeFeatureFlagsCxxInterop::useRuntimeShadowNodeReferenceUpdate(
return ReactNativeFeatureFlags::useRuntimeShadowNodeReferenceUpdate();
}
bool JReactNativeFeatureFlagsCxxInterop::useRuntimeShadowNodeReferenceUpdateOnLayout(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::useRuntimeShadowNodeReferenceUpdateOnLayout();
}
bool JReactNativeFeatureFlagsCxxInterop::useStateAlignmentMechanism(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::useStateAlignmentMechanism();
@@ -365,6 +376,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"useRuntimeShadowNodeReferenceUpdate",
JReactNativeFeatureFlagsCxxInterop::useRuntimeShadowNodeReferenceUpdate),
makeNativeMethod(
"useRuntimeShadowNodeReferenceUpdateOnLayout",
JReactNativeFeatureFlagsCxxInterop::useRuntimeShadowNodeReferenceUpdateOnLayout),
makeNativeMethod(
"useStateAlignmentMechanism",
JReactNativeFeatureFlagsCxxInterop::useStateAlignmentMechanism),
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<b8ba23ac6a30ed059f6bb5f6b7994c9f>>
* @generated SignedSource<<19fe3642ec462c23d361e0f036da887a>>
*/
/**
@@ -93,6 +93,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool useRuntimeShadowNodeReferenceUpdate(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
static bool useRuntimeShadowNodeReferenceUpdateOnLayout(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
static bool useStateAlignmentMechanism(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<5366e268a53215419a7271cd7fac76c9>>
* @generated SignedSource<<b7969efd5890b7be7be5fd8e6b0bf301>>
*/
/**
@@ -105,6 +105,10 @@ bool ReactNativeFeatureFlags::useRuntimeShadowNodeReferenceUpdate() {
return getAccessor().useRuntimeShadowNodeReferenceUpdate();
}
bool ReactNativeFeatureFlags::useRuntimeShadowNodeReferenceUpdateOnLayout() {
return getAccessor().useRuntimeShadowNodeReferenceUpdateOnLayout();
}
bool ReactNativeFeatureFlags::useStateAlignmentMechanism() {
return getAccessor().useStateAlignmentMechanism();
}
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<977b87c9478cea28cbb1aff61eef1fa4>>
* @generated SignedSource<<c4d88f9d9b8c6d5ca917d1ba9e53d9e8>>
*/
/**
@@ -142,6 +142,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool useRuntimeShadowNodeReferenceUpdate();
/**
* When enabled, cloning shadow nodes during layout will update the reference held by the current JS fiber tree.
*/
RN_EXPORT static bool useRuntimeShadowNodeReferenceUpdateOnLayout();
/**
* When enabled, it uses optimised state reconciliation algorithm.
*/
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a704a9fb56393c9ffaef917aacc26421>>
* @generated SignedSource<<5f27dd10824706ea065dc0340d46c409>>
*/
/**
@@ -407,6 +407,24 @@ bool ReactNativeFeatureFlagsAccessor::useRuntimeShadowNodeReferenceUpdate() {
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::useRuntimeShadowNodeReferenceUpdateOnLayout() {
auto flagValue = useRuntimeShadowNodeReferenceUpdateOnLayout_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(21, "useRuntimeShadowNodeReferenceUpdateOnLayout");
flagValue = currentProvider_->useRuntimeShadowNodeReferenceUpdateOnLayout();
useRuntimeShadowNodeReferenceUpdateOnLayout_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::useStateAlignmentMechanism() {
auto flagValue = useStateAlignmentMechanism_.load();
@@ -416,7 +434,7 @@ bool ReactNativeFeatureFlagsAccessor::useStateAlignmentMechanism() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(21, "useStateAlignmentMechanism");
markFlagAsAccessed(22, "useStateAlignmentMechanism");
flagValue = currentProvider_->useStateAlignmentMechanism();
useStateAlignmentMechanism_ = flagValue;
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<7de49cd344ee15e49e2a1cf5e78e0139>>
* @generated SignedSource<<8837dd1578561f205e6f682afd98c450>>
*/
/**
@@ -52,6 +52,7 @@ class ReactNativeFeatureFlagsAccessor {
bool useModernRuntimeScheduler();
bool useNativeViewConfigsInBridgelessMode();
bool useRuntimeShadowNodeReferenceUpdate();
bool useRuntimeShadowNodeReferenceUpdateOnLayout();
bool useStateAlignmentMechanism();
void override(std::unique_ptr<ReactNativeFeatureFlagsProvider> provider);
@@ -63,7 +64,7 @@ class ReactNativeFeatureFlagsAccessor {
std::unique_ptr<ReactNativeFeatureFlagsProvider> currentProvider_;
bool wasOverridden_;
std::array<std::atomic<const char*>, 22> accessedFeatureFlags_;
std::array<std::atomic<const char*>, 23> accessedFeatureFlags_;
std::atomic<std::optional<bool>> commonTestFlag_;
std::atomic<std::optional<bool>> allowCollapsableChildren_;
@@ -86,6 +87,7 @@ class ReactNativeFeatureFlagsAccessor {
std::atomic<std::optional<bool>> useModernRuntimeScheduler_;
std::atomic<std::optional<bool>> useNativeViewConfigsInBridgelessMode_;
std::atomic<std::optional<bool>> useRuntimeShadowNodeReferenceUpdate_;
std::atomic<std::optional<bool>> useRuntimeShadowNodeReferenceUpdateOnLayout_;
std::atomic<std::optional<bool>> useStateAlignmentMechanism_;
};
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<2466d6097301e3fa9d022cc8425c7b1c>>
* @generated SignedSource<<2a0324c7b8009e906b18db11c5d2beb9>>
*/
/**
@@ -111,6 +111,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider {
return false;
}
bool useRuntimeShadowNodeReferenceUpdateOnLayout() override {
return false;
}
bool useStateAlignmentMechanism() override {
return false;
}
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<6a05970506e696333c7480f6cf094642>>
* @generated SignedSource<<7cd3889fcccc029925651f7ef406ff40>>
*/
/**
@@ -46,6 +46,7 @@ class ReactNativeFeatureFlagsProvider {
virtual bool useModernRuntimeScheduler() = 0;
virtual bool useNativeViewConfigsInBridgelessMode() = 0;
virtual bool useRuntimeShadowNodeReferenceUpdate() = 0;
virtual bool useRuntimeShadowNodeReferenceUpdateOnLayout() = 0;
virtual bool useStateAlignmentMechanism() = 0;
};
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<f271827befadd5040d9d9ceb773349c5>>
* @generated SignedSource<<914fa03d71af61b82f05f005d3f3973d>>
*/
/**
@@ -142,6 +142,11 @@ bool NativeReactNativeFeatureFlags::useRuntimeShadowNodeReferenceUpdate(
return ReactNativeFeatureFlags::useRuntimeShadowNodeReferenceUpdate();
}
bool NativeReactNativeFeatureFlags::useRuntimeShadowNodeReferenceUpdateOnLayout(
jsi::Runtime& /*runtime*/) {
return ReactNativeFeatureFlags::useRuntimeShadowNodeReferenceUpdateOnLayout();
}
bool NativeReactNativeFeatureFlags::useStateAlignmentMechanism(
jsi::Runtime& /*runtime*/) {
return ReactNativeFeatureFlags::useStateAlignmentMechanism();
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<b42746e0a2c6e0611c8acc81502a0967>>
* @generated SignedSource<<1458397650db55d5a985685fa4998e41>>
*/
/**
@@ -77,6 +77,8 @@ class NativeReactNativeFeatureFlags
bool useRuntimeShadowNodeReferenceUpdate(jsi::Runtime& runtime);
bool useRuntimeShadowNodeReferenceUpdateOnLayout(jsi::Runtime& runtime);
bool useStateAlignmentMechanism(jsi::Runtime& runtime);
};
@@ -137,6 +137,11 @@ const definitions: FeatureFlagDefinitions = {
description:
'When enabled, cloning shadow nodes within react native will update the reference held by the current JS fiber tree.',
},
useRuntimeShadowNodeReferenceUpdateOnLayout: {
defaultValue: false,
description:
'When enabled, cloning shadow nodes during layout will update the reference held by the current JS fiber tree.',
},
useStateAlignmentMechanism: {
defaultValue: false,
description:
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<98d5ac48b23f6422020b49ed5d8732d0>>
* @generated SignedSource<<c3b421b10f05f33a9830fbd730a3786a>>
* @flow strict-local
*/
@@ -61,6 +61,7 @@ export type ReactNativeFeatureFlags = {
useModernRuntimeScheduler: Getter<boolean>,
useNativeViewConfigsInBridgelessMode: Getter<boolean>,
useRuntimeShadowNodeReferenceUpdate: Getter<boolean>,
useRuntimeShadowNodeReferenceUpdateOnLayout: Getter<boolean>,
useStateAlignmentMechanism: Getter<boolean>,
}
@@ -188,6 +189,10 @@ export const useNativeViewConfigsInBridgelessMode: Getter<boolean> = createNativ
* When enabled, cloning shadow nodes within react native will update the reference held by the current JS fiber tree.
*/
export const useRuntimeShadowNodeReferenceUpdate: Getter<boolean> = createNativeFlagGetter('useRuntimeShadowNodeReferenceUpdate', false);
/**
* When enabled, cloning shadow nodes during layout will update the reference held by the current JS fiber tree.
*/
export const useRuntimeShadowNodeReferenceUpdateOnLayout: Getter<boolean> = createNativeFlagGetter('useRuntimeShadowNodeReferenceUpdateOnLayout', false);
/**
* When enabled, it uses optimised state reconciliation algorithm.
*/
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<f977176e5fc8d2f70873b59c40cb25ea>>
* @generated SignedSource<<4a30969e69164b149af42698f94c3b28>>
* @flow strict-local
*/
@@ -44,6 +44,7 @@ export interface Spec extends TurboModule {
+useModernRuntimeScheduler?: () => boolean;
+useNativeViewConfigsInBridgelessMode?: () => boolean;
+useRuntimeShadowNodeReferenceUpdate?: () => boolean;
+useRuntimeShadowNodeReferenceUpdateOnLayout?: () => boolean;
+useStateAlignmentMechanism?: () => boolean;
}