From 12228e3d43ea473fe2e2e39871ff5def6a38c537 Mon Sep 17 00:00:00 2001 From: Nick Lefever Date: Mon, 17 Nov 2025 13:09:05 -0800 Subject: [PATCH] Add runtime validation of Props 2.0 output (#54461) Summary: Pull Request resolved: https://github.com/facebook/react-native/pull/54461 Compare the output from Props 1.5 with Props 2.0 to detect any missing props in the output coming from Props 2.0. The comparison doesn't run for initial mounts due to Props 1.5 not using the default property values to generate a diff, which is obviously leading to more properties being in the Props 1.5 output that aren't necessary. Changelog: [Internal] Reviewed By: sammy-SC, javache Differential Revision: D86577390 fbshipit-source-id: 8666fc3e5d6ddc588e7b934358eafc8a789ee491 --- .../react/fabric/FabricMountingManager.cpp | 101 +++++++++++++++++- 1 file changed, 98 insertions(+), 3 deletions(-) diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp index a8196314710..8b966236899 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/FabricMountingManager.cpp @@ -24,9 +24,9 @@ #include #include +#include #include #include -#include #include namespace facebook::react { @@ -54,6 +54,80 @@ void FabricMountingManager::onSurfaceStop(SurfaceId surfaceId) { namespace { +#ifdef REACT_NATIVE_DEBUG +// List of layout-only props extracted from ViewProps.kt used to filter out +// component props from Props 1.5 to validate the Props 2.0 output +inline bool isLayoutOnlyProp(const std::string& propName) { + static const std::vector layoutOnlyProps = { + // Flexbox Alignment + "alignItems", + "alignSelf", + "alignContent", + + // Flexbox Properties + "flex", + "flexBasis", + "flexDirection", + "flexGrow", + "flexShrink", + "flexWrap", + "justifyContent", + + // Gaps + "rowGap", + "columnGap", + "gap", + + // Display & Position + "display", + "position", + + // Positioning + "right", + "top", + "bottom", + "left", + "start", + "end", + + // Dimensions + "width", + "height", + "minWidth", + "maxWidth", + "minHeight", + "maxHeight", + + // Margins + "margin", + "marginVertical", + "marginHorizontal", + "marginLeft", + "marginRight", + "marginTop", + "marginBottom", + "marginStart", + "marginEnd", + + // Paddings + "padding", + "paddingVertical", + "paddingHorizontal", + "paddingLeft", + "paddingRight", + "paddingTop", + "paddingBottom", + "paddingStart", + "paddingEnd", + + // Other + "collapsable", + }; + return std::find(layoutOnlyProps.begin(), layoutOnlyProps.end(), propName) != + layoutOnlyProps.end(); +} +#endif + inline int getIntBufferSizeForType(CppMountItem::Type mountItemType) { switch (mountItemType) { case CppMountItem::Type::Create: @@ -232,8 +306,29 @@ jni::local_ref getProps( strcmp( newShadowView.componentName, newProps->getDiffPropsImplementationTarget()) == 0) { - return ReadableNativeMap::newObjectCxxArgs( - newProps->getDiffProps(oldProps)); + auto diff = newProps->getDiffProps(oldProps); + +#ifdef REACT_NATIVE_DEBUG + if (oldProps != nullptr) { + auto controlDiff = + diffDynamicProps(oldProps->rawProps, newProps->rawProps); + + for (const auto& [prop, value] : controlDiff.items()) { + if (diff.count(prop) == 0) { + // Skip layout-only props since they are not included in Props 2.0 + if (!isLayoutOnlyProp(prop.asString())) { + LOG(ERROR) << "Props diff validation failed: Props 1.5 has prop '" + << prop.asString() + << "' = " << (value != nullptr ? value : "NULL") + << " that Props 2.0 doesn't have for component " + << newShadowView.componentName; + } + } + } + } +#endif + + return ReadableNativeMap::newObjectCxxArgs(std::move(diff)); } if (ReactNativeFeatureFlags::enableAccumulatedUpdatesInRawPropsAndroid()) { if (oldProps == nullptr) {