From d523933a2fc197661d269fe1c5df9ac8ff35281f Mon Sep 17 00:00:00 2001 From: Dmitry Rykun Date: Tue, 28 Jan 2025 06:10:25 -0800 Subject: [PATCH] Lift dynamic prop merging to ConcreteComponentDescriptor (#48939) Summary: The `enableAccumulatedUpdatesInRawPropsAndroid` experiment needs additional context for finer setup. Specifically it needs to be conditionally enabled based on a component name. This information is not accessible form the `Props` constructor. This diff moves the experimental logic to `ConcreteComponentDescriptor`. Changelog: [Internal] Differential Revision: D68633985 --- .../core/ConcreteComponentDescriptor.h | 21 +++++++++++++------ .../ReactCommon/react/renderer/core/Props.cpp | 11 +--------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h b/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h index 4f61219e542ddd..3af4c6d1978a43 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -114,16 +115,24 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { rawProps.parse(rawPropsParser_); - auto shadowNodeProps = ShadowNodeT::Props(context, rawProps, props); + auto& rawPropsToConsume = rawProps; +#ifdef ANDROID + if (ReactNativeFeatureFlags::enableAccumulatedUpdatesInRawPropsAndroid()) { + auto& oldDynamicProps = props->rawProps; + auto newDynamicProps = rawProps.toDynamic(); + auto mergedDynamicProps = mergeDynamicProps( + oldDynamicProps, newDynamicProps, NullValueStrategy::Override); + rawPropsToConsume = RawProps{mergedDynamicProps}; + } +#endif + + auto shadowNodeProps = + ShadowNodeT::Props(context, rawPropsToConsume, props); // Use the new-style iterator // Note that we just check if `Props` has this flag set, no matter // the type of ShadowNode; it acts as the single global flag. if (ReactNativeFeatureFlags::enableCppPropsIteratorSetter()) { -#ifdef ANDROID - const auto& dynamic = shadowNodeProps->rawProps; -#else - const auto& dynamic = static_cast(rawProps); -#endif + const auto& dynamic = rawProps.toDynamic(); for (const auto& pair : dynamic.items()) { const auto& name = pair.first.getString(); shadowNodeProps->setProp( diff --git a/packages/react-native/ReactCommon/react/renderer/core/Props.cpp b/packages/react-native/ReactCommon/react/renderer/core/Props.cpp index a8bd7079d47289..0e0e6fd4513d06 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/Props.cpp +++ b/packages/react-native/ReactCommon/react/renderer/core/Props.cpp @@ -10,7 +10,6 @@ #include #include -#include "DynamicPropsUtilities.h" namespace facebook::react { @@ -32,15 +31,7 @@ void Props::initialize( ? sourceProps.nativeId : convertRawProp(context, rawProps, "nativeID", sourceProps.nativeId, {}); #ifdef ANDROID - if (ReactNativeFeatureFlags::enableAccumulatedUpdatesInRawPropsAndroid()) { - auto& oldRawProps = sourceProps.rawProps; - auto newRawProps = rawProps.toDynamic(filterObjectKeys); - auto mergedRawProps = mergeDynamicProps( - oldRawProps, newRawProps, NullValueStrategy::Override); - this->rawProps = mergedRawProps; - } else { - this->rawProps = rawProps.toDynamic(filterObjectKeys); - } + this->rawProps = rawProps.toDynamic(filterObjectKeys); #endif }