From 2ef59c988d572093ccd351c67e05a968eb5a496b Mon Sep 17 00:00:00 2001 From: Samuel Susla Date: Fri, 12 Apr 2024 02:47:01 -0700 Subject: [PATCH] move to unified feature flag system for new state reconciliation algorithm (#44022) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/44022 changelog: [internal] move the new state reconciliation algorithm to the unified feature flag system. Reviewed By: rubennorte Differential Revision: D55965530 fbshipit-source-id: 3edde0858a670e86dc2d1cb561f03f584ff21896 --- .../React/Fabric/RCTSurfacePresenter.mm | 4 --- .../ReactAndroid/api/ReactAndroid.api | 1 - .../react/config/ReactFeatureFlags.java | 3 --- .../featureflags/ReactNativeFeatureFlags.kt | 8 +++++- .../ReactNativeFeatureFlagsCxxAccessor.kt | 12 ++++++++- .../ReactNativeFeatureFlagsCxxInterop.kt | 4 ++- .../ReactNativeFeatureFlagsDefaults.kt | 4 ++- .../ReactNativeFeatureFlagsLocalAccessor.kt | 13 ++++++++- .../ReactNativeFeatureFlagsProvider.kt | 4 ++- .../src/main/jni/react/fabric/Binding.cpp | 2 -- .../JReactNativeFeatureFlagsCxxInterop.cpp | 16 ++++++++++- .../JReactNativeFeatureFlagsCxxInterop.h | 5 +++- .../featureflags/ReactNativeFeatureFlags.cpp | 6 ++++- .../featureflags/ReactNativeFeatureFlags.h | 7 ++++- .../ReactNativeFeatureFlagsAccessor.cpp | 20 +++++++++++++- .../ReactNativeFeatureFlagsAccessor.h | 6 +++-- .../ReactNativeFeatureFlagsDefaults.h | 6 ++++- .../ReactNativeFeatureFlagsProvider.h | 3 ++- .../NativeReactNativeFeatureFlags.cpp | 7 ++++- .../NativeReactNativeFeatureFlags.h | 4 ++- .../react/renderer/mounting/ShadowTree.cpp | 3 ++- .../tests/StateReconciliationTest.cpp | 27 +++++++++++++++++-- .../ReactCommon/react/utils/CoreFeatures.cpp | 1 - .../ReactCommon/react/utils/CoreFeatures.h | 3 --- .../ReactNativeFeatureFlags.config.js | 5 ++++ .../featureflags/ReactNativeFeatureFlags.js | 7 ++++- .../specs/NativeReactNativeFeatureFlags.js | 3 ++- 27 files changed, 148 insertions(+), 36 deletions(-) diff --git a/packages/react-native/React/Fabric/RCTSurfacePresenter.mm b/packages/react-native/React/Fabric/RCTSurfacePresenter.mm index b5e183a9c1d..c1c19cb191c 100644 --- a/packages/react-native/React/Fabric/RCTSurfacePresenter.mm +++ b/packages/react-native/React/Fabric/RCTSurfacePresenter.mm @@ -264,10 +264,6 @@ static BackgroundExecutor RCTGetBackgroundExecutor() CoreFeatures::enableGranularScrollViewStateUpdatesIOS = true; } - if (reactNativeConfig && reactNativeConfig->getBool("react_fabric:enable_cloneless_state_progression")) { - CoreFeatures::enableClonelessStateProgression = true; - } - auto componentRegistryFactory = [factory = wrapManagedObject(_mountingManager.componentViewRegistry.componentViewFactory)]( const EventDispatcher::Weak &eventDispatcher, const ContextContainer::Shared &contextContainer) { diff --git a/packages/react-native/ReactAndroid/api/ReactAndroid.api b/packages/react-native/ReactAndroid/api/ReactAndroid.api index 9cf4f232353..989c6900b71 100644 --- a/packages/react-native/ReactAndroid/api/ReactAndroid.api +++ b/packages/react-native/ReactAndroid/api/ReactAndroid.api @@ -1962,7 +1962,6 @@ public class com/facebook/react/config/ReactFeatureFlags { public static field dispatchPointerEvents Z public static field enableBridgelessArchitecture Z public static field enableBridgelessArchitectureNewCreateReloadDestroy Z - public static field enableClonelessStateProgression Z public static field enableCppPropsIteratorSetter Z public static field enableEagerRootViewAttachment Z public static field enableFabricLogs Z diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java index 78692480249..19f0d770abb 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java @@ -101,9 +101,6 @@ public class ReactFeatureFlags { */ public static boolean enableRemoveDeleteTreeInstruction = false; - /** When enabled, Fabric will avoid cloning notes to perform state progression. */ - public static boolean enableClonelessStateProgression = false; - /** When enabled, rawProps in Props will not include Yoga specific props. */ public static boolean excludeYogaFromRawProps = false; diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt index fe7273bf077..a10ff55dd8e 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt @@ -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<> + * @generated SignedSource<<7c2d825e15fc7e442034a598eebb6e25>> */ /** @@ -118,6 +118,12 @@ public object ReactNativeFeatureFlags { @JvmStatic public fun useNativeViewConfigsInBridgelessMode(): Boolean = accessor.useNativeViewConfigsInBridgelessMode() + /** + * When enabled, it uses optimised state reconciliation algorithm. + */ + @JvmStatic + public fun useStateAlignmentMechanism(): Boolean = accessor.useStateAlignmentMechanism() + /** * Overrides the feature flags with the ones provided by the given provider * (generally one that extends `ReactNativeFeatureFlagsDefaults`). diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt index 48ce01995a3..7488e94a0d6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt @@ -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<<51d66e841a09638375b1849043c9886a>> + * @generated SignedSource<> */ /** @@ -35,6 +35,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso private var inspectorEnableModernCDPRegistryCache: Boolean? = null private var useModernRuntimeSchedulerCache: Boolean? = null private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null + private var useStateAlignmentMechanismCache: Boolean? = null override fun commonTestFlag(): Boolean { var cached = commonTestFlagCache @@ -171,6 +172,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso return cached } + override fun useStateAlignmentMechanism(): Boolean { + var cached = useStateAlignmentMechanismCache + if (cached == null) { + cached = ReactNativeFeatureFlagsCxxInterop.useStateAlignmentMechanism() + useStateAlignmentMechanismCache = cached + } + return cached + } + override fun override(provider: ReactNativeFeatureFlagsProvider): Unit = ReactNativeFeatureFlagsCxxInterop.override(provider as Any) diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt index 0b6d013f751..a62bc3680f5 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt @@ -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<<4422f7984f27638cc2fb18230a6d042e>> + * @generated SignedSource<<0b1377acc1a7a2bed8bd6448a54ec91a>> */ /** @@ -58,6 +58,8 @@ public object ReactNativeFeatureFlagsCxxInterop { @DoNotStrip @JvmStatic public external fun useNativeViewConfigsInBridgelessMode(): Boolean + @DoNotStrip @JvmStatic public external fun useStateAlignmentMechanism(): Boolean + @DoNotStrip @JvmStatic public external fun override(provider: Any) @DoNotStrip @JvmStatic public external fun dangerouslyReset() diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt index 2c0cbcbd775..b58b7e73968 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt @@ -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<> + * @generated SignedSource<<545ef5d7c16c2d6599f15a747c53cf3f>> */ /** @@ -52,4 +52,6 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi override fun useModernRuntimeScheduler(): Boolean = false override fun useNativeViewConfigsInBridgelessMode(): Boolean = false + + override fun useStateAlignmentMechanism(): Boolean = false } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt index 2f3ec5922e6..69e028208e6 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt @@ -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<<46793ec55ed15661090a9b9998806bcc>> + * @generated SignedSource<> */ /** @@ -39,6 +39,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces private var inspectorEnableModernCDPRegistryCache: Boolean? = null private var useModernRuntimeSchedulerCache: Boolean? = null private var useNativeViewConfigsInBridgelessModeCache: Boolean? = null + private var useStateAlignmentMechanismCache: Boolean? = null override fun commonTestFlag(): Boolean { var cached = commonTestFlagCache @@ -190,6 +191,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces return cached } + override fun useStateAlignmentMechanism(): Boolean { + var cached = useStateAlignmentMechanismCache + if (cached == null) { + cached = currentProvider.useStateAlignmentMechanism() + accessedFeatureFlags.add("useStateAlignmentMechanism") + useStateAlignmentMechanismCache = cached + } + return cached + } + override fun override(provider: ReactNativeFeatureFlagsProvider) { if (accessedFeatureFlags.isNotEmpty()) { val accessedFeatureFlagsStr = accessedFeatureFlags.joinToString(separator = ", ") { it } diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt index 48c47e13263..ef201023ea3 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt @@ -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<> + * @generated SignedSource<> */ /** @@ -52,4 +52,6 @@ public interface ReactNativeFeatureFlagsProvider { @DoNotStrip public fun useModernRuntimeScheduler(): Boolean @DoNotStrip public fun useNativeViewConfigsInBridgelessMode(): Boolean + + @DoNotStrip public fun useStateAlignmentMechanism(): Boolean } diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp index 357e8e7791f..0c9373fcbdd 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/Binding.cpp @@ -406,8 +406,6 @@ void Binding::installFabricUIManager( CoreFeatures::enablePropIteratorSetter = getFeatureFlagValue("enableCppPropsIteratorSetter"); - CoreFeatures::enableClonelessStateProgression = - getFeatureFlagValue("enableClonelessStateProgression"); CoreFeatures::excludeYogaFromRawProps = getFeatureFlagValue("excludeYogaFromRawProps"); diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp index 6eefe64e4ff..a7ddc0b3d78 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp @@ -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<<3a7d633de9e6fd6862864c202d56523a>> + * @generated SignedSource<<82163a04d1e3cb54d6c5125173ab807f>> */ /** @@ -129,6 +129,12 @@ class ReactNativeFeatureFlagsProviderHolder return method(javaProvider_); } + bool useStateAlignmentMechanism() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("useStateAlignmentMechanism"); + return method(javaProvider_); + } + private: jni::global_ref javaProvider_; }; @@ -208,6 +214,11 @@ bool JReactNativeFeatureFlagsCxxInterop::useNativeViewConfigsInBridgelessMode( return ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode(); } +bool JReactNativeFeatureFlagsCxxInterop::useStateAlignmentMechanism( + facebook::jni::alias_ref /*unused*/) { + return ReactNativeFeatureFlags::useStateAlignmentMechanism(); +} + void JReactNativeFeatureFlagsCxxInterop::override( facebook::jni::alias_ref /*unused*/, jni::alias_ref provider) { @@ -270,6 +281,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() { makeNativeMethod( "useNativeViewConfigsInBridgelessMode", JReactNativeFeatureFlagsCxxInterop::useNativeViewConfigsInBridgelessMode), + makeNativeMethod( + "useStateAlignmentMechanism", + JReactNativeFeatureFlagsCxxInterop::useStateAlignmentMechanism), }); } diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h index 047cf2c8e30..ab28c2198c3 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h @@ -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<<7237412cb02dad9468f144a050bd78e3>> + * @generated SignedSource<<48e337d37416ab988ea747050bf207f3>> */ /** @@ -75,6 +75,9 @@ class JReactNativeFeatureFlagsCxxInterop static bool useNativeViewConfigsInBridgelessMode( facebook::jni::alias_ref); + static bool useStateAlignmentMechanism( + facebook::jni::alias_ref); + static void override( facebook::jni::alias_ref, jni::alias_ref provider); diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp index 43864710f1b..496dd16a361 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp @@ -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<> + * @generated SignedSource<> */ /** @@ -81,6 +81,10 @@ bool ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode() { return getAccessor().useNativeViewConfigsInBridgelessMode(); } +bool ReactNativeFeatureFlags::useStateAlignmentMechanism() { + return getAccessor().useStateAlignmentMechanism(); +} + void ReactNativeFeatureFlags::override( std::unique_ptr provider) { getAccessor().override(std::move(provider)); diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h index 736feebfd2d..ddc2631fd50 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h @@ -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<<38881afec04f45eff46edd99ce9443da>> + * @generated SignedSource<<8804fc52ad516ba82c0db6fcdea5f110>> */ /** @@ -112,6 +112,11 @@ class ReactNativeFeatureFlags { */ RN_EXPORT static bool useNativeViewConfigsInBridgelessMode(); + /** + * When enabled, it uses optimised state reconciliation algorithm. + */ + RN_EXPORT static bool useStateAlignmentMechanism(); + /** * Overrides the feature flags with the ones provided by the given provider * (generally one that extends `ReactNativeFeatureFlagsDefaults`). diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp index 799111c21ba..6b296c18949 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp @@ -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<<21980ab4688bc93c5573012a228e3997>> + * @generated SignedSource<<9f5c5313e139b450449e2716735c26e7>> */ /** @@ -299,6 +299,24 @@ bool ReactNativeFeatureFlagsAccessor::useNativeViewConfigsInBridgelessMode() { return flagValue.value(); } +bool ReactNativeFeatureFlagsAccessor::useStateAlignmentMechanism() { + auto flagValue = useStateAlignmentMechanism_.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(15, "useStateAlignmentMechanism"); + + flagValue = currentProvider_->useStateAlignmentMechanism(); + useStateAlignmentMechanism_ = flagValue; + } + + return flagValue.value(); +} + void ReactNativeFeatureFlagsAccessor::override( std::unique_ptr provider) { if (wasOverridden_) { diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h index aab11cf3a90..f48b7c13eaa 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h @@ -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<> + * @generated SignedSource<> */ /** @@ -46,6 +46,7 @@ class ReactNativeFeatureFlagsAccessor { bool inspectorEnableModernCDPRegistry(); bool useModernRuntimeScheduler(); bool useNativeViewConfigsInBridgelessMode(); + bool useStateAlignmentMechanism(); void override(std::unique_ptr provider); @@ -56,7 +57,7 @@ class ReactNativeFeatureFlagsAccessor { std::unique_ptr currentProvider_; bool wasOverridden_; - std::array, 15> accessedFeatureFlags_; + std::array, 16> accessedFeatureFlags_; std::atomic> commonTestFlag_; std::atomic> batchRenderingUpdatesInEventLoop_; @@ -73,6 +74,7 @@ class ReactNativeFeatureFlagsAccessor { std::atomic> inspectorEnableModernCDPRegistry_; std::atomic> useModernRuntimeScheduler_; std::atomic> useNativeViewConfigsInBridgelessMode_; + std::atomic> useStateAlignmentMechanism_; }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h index 7dc384f8637..ae8cd41420e 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h @@ -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<<72058f22fd21f03e66136929306d5974>> + * @generated SignedSource<<008818e7f2d8b9e295704cccc33758e7>> */ /** @@ -86,6 +86,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider { bool useNativeViewConfigsInBridgelessMode() override { return false; } + + bool useStateAlignmentMechanism() override { + return false; + } }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h index 7e1237ae370..32e9bc271a1 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h @@ -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<<21fb3f2ea9db49ea4710a13807c7512a>> + * @generated SignedSource<<270291da73cb3e4eddc7bd5cdc9a9470>> */ /** @@ -40,6 +40,7 @@ class ReactNativeFeatureFlagsProvider { virtual bool inspectorEnableModernCDPRegistry() = 0; virtual bool useModernRuntimeScheduler() = 0; virtual bool useNativeViewConfigsInBridgelessMode() = 0; + virtual bool useStateAlignmentMechanism() = 0; }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp index 2096238d12e..60dea7a12db 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp @@ -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<<55ee96b1902071c987c70b5f07f670e4>> + * @generated SignedSource<<1abf19f9d1352105511e86c0f217de7a>> */ /** @@ -112,4 +112,9 @@ bool NativeReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode( return ReactNativeFeatureFlags::useNativeViewConfigsInBridgelessMode(); } +bool NativeReactNativeFeatureFlags::useStateAlignmentMechanism( + jsi::Runtime& /*runtime*/) { + return ReactNativeFeatureFlags::useStateAlignmentMechanism(); +} + } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h index fc233e23a49..fcd022ff96a 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h @@ -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<> + * @generated SignedSource<<7a2a41f80549322a7f4255d193dc0b7b>> */ /** @@ -64,6 +64,8 @@ class NativeReactNativeFeatureFlags bool useModernRuntimeScheduler(jsi::Runtime& runtime); bool useNativeViewConfigsInBridgelessMode(jsi::Runtime& runtime); + + bool useStateAlignmentMechanism(jsi::Runtime& runtime); }; } // namespace facebook::react diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.cpp index fd317991511..45054ef8eb1 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/ShadowTree.cpp @@ -8,6 +8,7 @@ #include "ShadowTree.h" #include +#include #include #include #include @@ -453,7 +454,7 @@ CommitStatus ShadowTree::tryCommit( } if (commitOptions.enableStateReconciliation) { - if (CoreFeatures::enableClonelessStateProgression) { + if (ReactNativeFeatureFlags::useStateAlignmentMechanism()) { progressStateIfNecessary(*newRootShadowNode, *oldRootShadowNode); } else { auto updatedNewRootShadowNode = diff --git a/packages/react-native/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp b/packages/react-native/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp index 1ef49950a95..006b5936e3a 100644 --- a/packages/react-native/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp +++ b/packages/react-native/ReactCommon/react/renderer/mounting/tests/StateReconciliationTest.cpp @@ -9,6 +9,8 @@ #include +#include +#include #include #include #include @@ -22,6 +24,20 @@ using namespace facebook::react; +class StateReconciliationTestFeatureFlags + : public ReactNativeFeatureFlagsDefaults { + public: + explicit StateReconciliationTestFeatureFlags(bool useStateAlignmentMechanism) + : useStateAlignmentMechanism_(useStateAlignmentMechanism) {} + + bool useStateAlignmentMechanism() override { + return useStateAlignmentMechanism_; + } + + private: + bool useStateAlignmentMechanism_; +}; + class DummyShadowTreeDelegate : public ShadowTreeDelegate { public: RootShadowNode::Unshared shadowTreeWillCommit( @@ -64,8 +80,15 @@ const ShadowNode* findDescendantNode( class StateReconciliationTest : public ::testing::TestWithParam { public: - StateReconciliationTest() : builder_(simpleComponentBuilder()) { - CoreFeatures::enableClonelessStateProgression = GetParam(); + StateReconciliationTest() : builder_(simpleComponentBuilder()) {} + + void SetUp() override { + ReactNativeFeatureFlags::override( + std::make_unique(GetParam())); + } + + void TearDown() override { + ReactNativeFeatureFlags::dangerouslyReset(); } ComponentBuilder builder_; diff --git a/packages/react-native/ReactCommon/react/utils/CoreFeatures.cpp b/packages/react-native/ReactCommon/react/utils/CoreFeatures.cpp index dd651affc98..f9355f2b76e 100644 --- a/packages/react-native/ReactCommon/react/utils/CoreFeatures.cpp +++ b/packages/react-native/ReactCommon/react/utils/CoreFeatures.cpp @@ -12,7 +12,6 @@ namespace facebook::react { bool CoreFeatures::enablePropIteratorSetter = false; bool CoreFeatures::enableGranularScrollViewStateUpdatesIOS = false; bool CoreFeatures::enableGranularShadowTreeStateReconciliation = false; -bool CoreFeatures::enableClonelessStateProgression = false; bool CoreFeatures::excludeYogaFromRawProps = false; bool CoreFeatures::enableReportEventPaintTime = false; diff --git a/packages/react-native/ReactCommon/react/utils/CoreFeatures.h b/packages/react-native/ReactCommon/react/utils/CoreFeatures.h index ba9e9b030f5..acc54a05d0d 100644 --- a/packages/react-native/ReactCommon/react/utils/CoreFeatures.h +++ b/packages/react-native/ReactCommon/react/utils/CoreFeatures.h @@ -27,9 +27,6 @@ class CoreFeatures { // state and the last commit that updated state changed before committing. static bool enableGranularShadowTreeStateReconciliation; - // When enabled, Fabric will avoid cloning notes to perform state progression. - static bool enableClonelessStateProgression; - // When enabled, rawProps in Props will not include Yoga specific props. static bool excludeYogaFromRawProps; diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js index 54ad2c8aaf8..aba1b62f9d3 100644 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -101,6 +101,11 @@ const definitions: FeatureFlagDefinitions = { description: 'When enabled, the native view configs are used in bridgeless mode.', }, + useStateAlignmentMechanism: { + defaultValue: false, + description: + 'When enabled, it uses optimised state reconciliation algorithm.', + }, }, jsOnly: { diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index 867f39004fb..7b46e29f731 100644 --- a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js @@ -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<<45969617730126d45f35820ee3bd5853>> + * @generated SignedSource<<39fd96ed670e0acae857e7fce3377452>> * @flow strict-local */ @@ -55,6 +55,7 @@ export type ReactNativeFeatureFlags = { inspectorEnableModernCDPRegistry: Getter, useModernRuntimeScheduler: Getter, useNativeViewConfigsInBridgelessMode: Getter, + useStateAlignmentMechanism: Getter, } /** @@ -157,6 +158,10 @@ export const useModernRuntimeScheduler: Getter = createNativeFlagGetter * When enabled, the native view configs are used in bridgeless mode. */ export const useNativeViewConfigsInBridgelessMode: Getter = createNativeFlagGetter('useNativeViewConfigsInBridgelessMode', false); +/** + * When enabled, it uses optimised state reconciliation algorithm. + */ +export const useStateAlignmentMechanism: Getter = createNativeFlagGetter('useStateAlignmentMechanism', false); /** * Overrides the feature flags with the provided methods. diff --git a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js index 9331c6242fe..28a6de2e5c9 100644 --- a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js @@ -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<<22dd9936df00ce7a53a5aa4a2c331279>> + * @generated SignedSource<<99ddb55dadff7adfb02c105984d47cbf>> * @flow strict-local */ @@ -38,6 +38,7 @@ export interface Spec extends TurboModule { +inspectorEnableModernCDPRegistry?: () => boolean; +useModernRuntimeScheduler?: () => boolean; +useNativeViewConfigsInBridgelessMode?: () => boolean; + +useStateAlignmentMechanism?: () => boolean; } const NativeReactNativeFeatureFlags: ?Spec = TurboModuleRegistry.get(