diff --git a/ReactCommon/fabric/core/componentdescriptor/ComponentDescriptor.h b/ReactCommon/fabric/core/componentdescriptor/ComponentDescriptor.h index ea2952ce291..c9d2feb75af 100644 --- a/ReactCommon/fabric/core/componentdescriptor/ComponentDescriptor.h +++ b/ReactCommon/fabric/core/componentdescriptor/ComponentDescriptor.h @@ -98,6 +98,7 @@ class ComponentDescriptor { * `props` and `rawProps` applied on top of this. * If `props` is `nullptr`, a default `Props` object (with default values) * will be used. + * Must return an object which is NOT pointer equal to `props`. */ virtual SharedProps cloneProps( const SharedProps &props, diff --git a/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h b/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h index 142e0dd2aad..7b7550447e6 100644 --- a/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h +++ b/ReactCommon/fabric/core/componentdescriptor/ConcreteComponentDescriptor.h @@ -108,8 +108,13 @@ class ConcreteComponentDescriptor : public ComponentDescriptor { dynamic_cast(props.get()) && "Provided `props` has an incompatible type."); - if (rawProps.isEmpty()) { - return props ? props : ShadowNodeT::defaultSharedProps(); + // Optimization: + // Quite often nodes are constructed with default/empty props: the base + // `props` object is `null` (there no base because it's not cloning) and the + // `rawProps` is empty. In this case, we can return the default props object + // of a concrete type entirely bypassing parsing. + if (!props && rawProps.isEmpty()) { + return ShadowNodeT::defaultSharedProps(); } rawProps.parse(rawPropsParser_); diff --git a/ReactCommon/fabric/core/tests/ComponentDescriptorTest.cpp b/ReactCommon/fabric/core/tests/ComponentDescriptorTest.cpp index 1dfc1878eff..58baadffb32 100644 --- a/ReactCommon/fabric/core/tests/ComponentDescriptorTest.cpp +++ b/ReactCommon/fabric/core/tests/ComponentDescriptorTest.cpp @@ -72,6 +72,9 @@ TEST(ComponentDescriptorTest, cloneShadowNode) { EXPECT_EQ(cloned->getTag(), 9); EXPECT_EQ(cloned->getSurfaceId(), 1); EXPECT_STREQ(cloned->getProps()->nativeId.c_str(), "abc"); + + auto clonedButSameProps = descriptor->cloneProps(props, RawProps()); + EXPECT_NE(clonedButSameProps, props); } TEST(ComponentDescriptorTest, appendChild) {