Skip to content

Commit 25ba26f

Browse files
Dmitry Rykunfacebook-github-bot
authored andcommitted
Lift dynamic prop merging to ConcreteComponentDescriptor (react#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
1 parent 67981ef commit 25ba26f

2 files changed

Lines changed: 15 additions & 16 deletions

File tree

packages/react-native/ReactCommon/react/renderer/core/ConcreteComponentDescriptor.h

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <react/debug/react_native_assert.h>
1414
#include <react/featureflags/ReactNativeFeatureFlags.h>
1515
#include <react/renderer/core/ComponentDescriptor.h>
16+
#include <react/renderer/core/DynamicPropsUtilities.h>
1617
#include <react/renderer/core/EventDispatcher.h>
1718
#include <react/renderer/core/Props.h>
1819
#include <react/renderer/core/PropsParserContext.h>
@@ -114,16 +115,23 @@ class ConcreteComponentDescriptor : public ComponentDescriptor {
114115

115116
rawProps.parse(rawPropsParser_);
116117

117-
auto shadowNodeProps = ShadowNodeT::Props(context, rawProps, props);
118+
std::optional<RawProps> mergedRawProps = std::nullopt;
119+
#ifdef ANDROID
120+
if (ReactNativeFeatureFlags::enableAccumulatedUpdatesInRawPropsAndroid()) {
121+
mergedRawProps.emplace(RawProps{mergeDynamicProps(
122+
props->rawProps, rawProps.toDynamic(), NullValueStrategy::Override)});
123+
}
124+
#endif
125+
auto shadowNodeProps = ShadowNodeT::Props(
126+
context,
127+
mergedRawProps.has_value() ? *mergedRawProps : rawProps,
128+
props);
129+
118130
// Use the new-style iterator
119131
// Note that we just check if `Props` has this flag set, no matter
120132
// the type of ShadowNode; it acts as the single global flag.
121133
if (ReactNativeFeatureFlags::enableCppPropsIteratorSetter()) {
122-
#ifdef ANDROID
123-
const auto& dynamic = shadowNodeProps->rawProps;
124-
#else
125-
const auto& dynamic = static_cast<folly::dynamic>(rawProps);
126-
#endif
134+
const auto& dynamic = rawProps.toDynamic();
127135
for (const auto& pair : dynamic.items()) {
128136
const auto& name = pair.first.getString();
129137
shadowNodeProps->setProp(

packages/react-native/ReactCommon/react/renderer/core/Props.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
#include <react/renderer/core/propsConversions.h>
1111

1212
#include <react/featureflags/ReactNativeFeatureFlags.h>
13-
#include "DynamicPropsUtilities.h"
1413

1514
namespace facebook::react {
1615

@@ -32,15 +31,7 @@ void Props::initialize(
3231
? sourceProps.nativeId
3332
: convertRawProp(context, rawProps, "nativeID", sourceProps.nativeId, {});
3433
#ifdef ANDROID
35-
if (ReactNativeFeatureFlags::enableAccumulatedUpdatesInRawPropsAndroid()) {
36-
auto& oldRawProps = sourceProps.rawProps;
37-
auto newRawProps = rawProps.toDynamic(filterObjectKeys);
38-
auto mergedRawProps = mergeDynamicProps(
39-
oldRawProps, newRawProps, NullValueStrategy::Override);
40-
this->rawProps = mergedRawProps;
41-
} else {
42-
this->rawProps = rawProps.toDynamic(filterObjectKeys);
43-
}
34+
this->rawProps = rawProps.toDynamic(filterObjectKeys);
4435
#endif
4536
}
4637

0 commit comments

Comments
 (0)