diff --git a/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp b/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp index 01c76f6385e..d3a91fdfa35 100644 --- a/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp +++ b/ReactCommon/react/renderer/components/view/AccessibilityProps.cpp @@ -166,7 +166,30 @@ AccessibilityProps::AccessibilityProps( rawProps, "testID", sourceProps.testId, - "")) {} + "")) { + // It is a (severe!) perf deoptimization to request props out-of-order. + // Thus, since we need to request the same prop twice here + // (accessibilityRole) we "must" do them subsequently here to prevent + // a regression. It is reasonable to ask if the `at` function can be improved; + // it probably can, but this is a fairly rare edge-case that (1) is easy-ish + // to work around here, and (2) would require very careful work to address + // this case and not regress the more common cases. + if (!enablePropIteratorSetter) { + const auto *rawPropValue = + rawProps.at("accessibilityRole", nullptr, nullptr); + AccessibilityTraits traits; + std::string roleString; + if (rawPropValue == nullptr || !rawPropValue->hasValue()) { + traits = AccessibilityTraits::None; + roleString = ""; + } else { + fromRawValue(context, *rawPropValue, traits); + fromRawValue(context, *rawPropValue, roleString); + } + accessibilityTraits = traits; + accessibilityRole = roleString; + } +} void AccessibilityProps::setProp( const PropsParserContext &context,