diff --git a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp index 398e5e9af6f..f72d8f092c1 100644 --- a/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp +++ b/packages/react-native/ReactCommon/yoga/yoga/algorithm/CalculateLayout.cpp @@ -271,10 +271,18 @@ static void computeFlexBasisForChild( resolvedFlexBasis.isDefined() && yoga::isDefined(mainAxisSize); if (useResolvedFlexBasis) { + // A basis computed earlier in this layout may come from the item's + // content, if the container was first measured with no main size. Replace + // it once the container has an exact main size, where the items flex from + // their flex bases. A container sized by its content within an available + // size keeps it, as the item's contribution to that size. + const bool hasExactMainSize = + (isMainAxisRow ? widthMode : heightMode) == SizingMode::StretchFit; if (child->getLayout().computedFlexBasis.isUndefined() || (child->getConfig()->isExperimentalFeatureEnabled( ExperimentalFeature::WebFlexBasis) && - child->getLayout().computedFlexBasisGeneration != generationCount)) { + (hasExactMainSize || + child->getLayout().computedFlexBasisGeneration != generationCount))) { const FloatOptional paddingAndBorder = FloatOptional( paddingAndBorderForAxis(child, mainAxis, direction, ownerWidth)); child->setLayoutComputedFlexBasis(