Re-land: fixYogaFlexBasisFitContentInMainAxis (#56064)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/56064

X-link: https://github.com/facebook/yoga/pull/1917

Re-land of D94658492 with fixes, which was reverted in D95669495.

## Context

D94658492 added the `fixYogaFlexBasisFitContentInMainAxis` flag to avoid unnecessary re-measurement cascades in Yoga. When Yoga computes flex basis for container children, the legacy behavior applies a `FitContent` constraint in the main axis, bounding the child's measurement by the parent's available space. This creates a dependency between the child's flex basis and the parent's content-determined size — when one sibling changes size, all siblings get re-measured and their shadow nodes get cloned unnecessarily.

The fix switches from `FitContent` to `MaxContent` for non-measure container children under auto-height parents, making each child's flex basis independent of the parent's size.

## What went wrong

D94658492 modeled the fix as a `YogaErrata` bit (`FLEX_BASIS_FIT_CONTENT_IN_MAIN_AXIS`). Errata flags are bitmasks, and apps that opt into `ALL` or `CLASSIC` errata (like IGVR and Airwave) inadvertently picked up the new behavior without explicitly enabling the feature flag, causing breakages.

## What changed in this re-land

This diff models the fix as a `YogaExperimentalFeature` (`FIX_FLEX_BASIS_FIT_CONTENT`) instead of a `YogaErrata` bit. Experimental features are individually opt-in, so existing apps won't accidentally pick up the change.

This diff only wires up the RN feature flag infrastructure (flag defaults to `false`). The iOS MobileConfig override and the Yoga layout logic will be landed in follow-up diffs.

changelog: [internal]

Reviewed By: javache, NickGerleman

Differential Revision: D95852922

fbshipit-source-id: e2b1aa7a5d8f340011123679f721c62396b5caa5
This commit is contained in:
Samuel Susla authored and meta-codesync[bot] committed 2026-03-12 14:27:49 -07:00
1 parent de82d61f3b
commit ebb2feed67
27 files changed
+266 -65

No files matched your search

@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<039798c50526ff1abf33bc7987aa78a9>>
* @generated SignedSource<<5144fb0350b71394206d614c68ef87f0>>
*/
/**
@@ -390,6 +390,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun fixTextClippingAndroid15useBoundsForWidth(): Boolean = accessor.fixTextClippingAndroid15useBoundsForWidth()
/**
* Fix flex basis computation to not apply FitContent constraint in the main axis for non-measure container nodes, preventing unnecessary re-measurement in scroll containers.
*/
@JvmStatic
public fun fixYogaFlexBasisFitContentInMainAxis(): Boolean = accessor.fixYogaFlexBasisFitContentInMainAxis()
/**
* Enable system assertion validating that Fusebox is configured with a single host. When set, the CDP backend will dynamically disable features (Perf and Network) in the event that multiple hosts are registered (undefined behaviour), and broadcast this over `ReactNativeApplication.systemStateChanged`.
*/
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<cbc85fcd815ba2585166a53e7b410f30>>
* @generated SignedSource<<d284f066f036908977797a381a044dfa>>
*/
/**
@@ -80,6 +80,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
private var fixFindShadowNodeByTagRaceConditionCache: Boolean? = null
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
private var fixTextClippingAndroid15useBoundsForWidthCache: Boolean? = null
private var fixYogaFlexBasisFitContentInMainAxisCache: Boolean? = null
private var fuseboxAssertSingleHostStateCache: Boolean? = null
private var fuseboxEnabledReleaseCache: Boolean? = null
private var fuseboxFrameRecordingEnabledCache: Boolean? = null
@@ -650,6 +651,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
return cached
}
override fun fixYogaFlexBasisFitContentInMainAxis(): Boolean {
var cached = fixYogaFlexBasisFitContentInMainAxisCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.fixYogaFlexBasisFitContentInMainAxis()
fixYogaFlexBasisFitContentInMainAxisCache = cached
}
return cached
}
override fun fuseboxAssertSingleHostState(): Boolean {
var cached = fuseboxAssertSingleHostStateCache
if (cached == null) {
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<3d472893c05bdee6e09f834f52d3d92f>>
* @generated SignedSource<<de1c66a540520cd88c4d358ba30f2c6d>>
*/
/**
@@ -148,6 +148,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
@DoNotStrip @JvmStatic public external fun fixTextClippingAndroid15useBoundsForWidth(): Boolean
@DoNotStrip @JvmStatic public external fun fixYogaFlexBasisFitContentInMainAxis(): Boolean
@DoNotStrip @JvmStatic public external fun fuseboxAssertSingleHostState(): Boolean
@DoNotStrip @JvmStatic public external fun fuseboxEnabledRelease(): Boolean
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<29f7031f91527f41f2f184596c542a5b>>
* @generated SignedSource<<ab3b1d2277b8cc9db1708ef94515fb35>>
*/
/**
@@ -143,6 +143,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
override fun fixTextClippingAndroid15useBoundsForWidth(): Boolean = false
override fun fixYogaFlexBasisFitContentInMainAxis(): Boolean = false
override fun fuseboxAssertSingleHostState(): Boolean = true
override fun fuseboxEnabledRelease(): Boolean = false
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<014ee4afdf58a61c9974df198068d81a>>
* @generated SignedSource<<7b87f5541ecf881d8ce51c5edd5b99b0>>
*/
/**
@@ -84,6 +84,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
private var fixFindShadowNodeByTagRaceConditionCache: Boolean? = null
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
private var fixTextClippingAndroid15useBoundsForWidthCache: Boolean? = null
private var fixYogaFlexBasisFitContentInMainAxisCache: Boolean? = null
private var fuseboxAssertSingleHostStateCache: Boolean? = null
private var fuseboxEnabledReleaseCache: Boolean? = null
private var fuseboxFrameRecordingEnabledCache: Boolean? = null
@@ -714,6 +715,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
return cached
}
override fun fixYogaFlexBasisFitContentInMainAxis(): Boolean {
var cached = fixYogaFlexBasisFitContentInMainAxisCache
if (cached == null) {
cached = currentProvider.fixYogaFlexBasisFitContentInMainAxis()
accessedFeatureFlags.add("fixYogaFlexBasisFitContentInMainAxis")
fixYogaFlexBasisFitContentInMainAxisCache = cached
}
return cached
}
override fun fuseboxAssertSingleHostState(): Boolean {
var cached = fuseboxAssertSingleHostStateCache
if (cached == null) {
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<acd57b19a67924a91c6b25904cb24d3b>>
* @generated SignedSource<<f34b257861830bae7012fc5201904831>>
*/
/**
@@ -143,6 +143,8 @@ public interface ReactNativeFeatureFlagsProvider {
@DoNotStrip public fun fixTextClippingAndroid15useBoundsForWidth(): Boolean
@DoNotStrip public fun fixYogaFlexBasisFitContentInMainAxis(): Boolean
@DoNotStrip public fun fuseboxAssertSingleHostState(): Boolean
@DoNotStrip public fun fuseboxEnabledRelease(): Boolean
@@ -10,7 +10,8 @@
package com.facebook.yoga;
public enum YogaExperimentalFeature {
WEB_FLEX_BASIS(0);
WEB_FLEX_BASIS(0),
FIX_FLEX_BASIS_FIT_CONTENT(1);
private final int mIntValue;
@@ -25,6 +26,7 @@ public enum YogaExperimentalFeature {
public static YogaExperimentalFeature fromInt(int value) {
switch (value) {
case 0: return WEB_FLEX_BASIS;
case 1: return FIX_FLEX_BASIS_FIT_CONTENT;
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<a753500d987b8719f0ba1bba8d3e4dc4>>
* @generated SignedSource<<b4670c40175b42e04eb8f03b752a0c00>>
*/
/**
@@ -399,6 +399,12 @@ class ReactNativeFeatureFlagsJavaProvider
return method(javaProvider_);
}
bool fixYogaFlexBasisFitContentInMainAxis() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("fixYogaFlexBasisFitContentInMainAxis");
return method(javaProvider_);
}
bool fuseboxAssertSingleHostState() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("fuseboxAssertSingleHostState");
@@ -877,6 +883,11 @@ bool JReactNativeFeatureFlagsCxxInterop::fixTextClippingAndroid15useBoundsForWid
return ReactNativeFeatureFlags::fixTextClippingAndroid15useBoundsForWidth();
}
bool JReactNativeFeatureFlagsCxxInterop::fixYogaFlexBasisFitContentInMainAxis(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::fixYogaFlexBasisFitContentInMainAxis();
}
bool JReactNativeFeatureFlagsCxxInterop::fuseboxAssertSingleHostState(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::fuseboxAssertSingleHostState();
@@ -1233,6 +1244,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"fixTextClippingAndroid15useBoundsForWidth",
JReactNativeFeatureFlagsCxxInterop::fixTextClippingAndroid15useBoundsForWidth),
makeNativeMethod(
"fixYogaFlexBasisFitContentInMainAxis",
JReactNativeFeatureFlagsCxxInterop::fixYogaFlexBasisFitContentInMainAxis),
makeNativeMethod(
"fuseboxAssertSingleHostState",
JReactNativeFeatureFlagsCxxInterop::fuseboxAssertSingleHostState),
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<6ff305bf95e95cd8a65c138fc24b43f8>>
* @generated SignedSource<<5433b4a2f4a0574591a38017422edac8>>
*/
/**
@@ -210,6 +210,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool fixTextClippingAndroid15useBoundsForWidth(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
static bool fixYogaFlexBasisFitContentInMainAxis(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
static bool fuseboxAssertSingleHostState(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<903b6404deb3339d2cfeced5be354134>>
* @generated SignedSource<<bfb72cee88230c56d2c101be808ef300>>
*/
/**
@@ -266,6 +266,10 @@ bool ReactNativeFeatureFlags::fixTextClippingAndroid15useBoundsForWidth() {
return getAccessor().fixTextClippingAndroid15useBoundsForWidth();
}
bool ReactNativeFeatureFlags::fixYogaFlexBasisFitContentInMainAxis() {
return getAccessor().fixYogaFlexBasisFitContentInMainAxis();
}
bool ReactNativeFeatureFlags::fuseboxAssertSingleHostState() {
return getAccessor().fuseboxAssertSingleHostState();
}
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<5ae89f16fbc942bd1c857c85b0520a03>>
* @generated SignedSource<<4811a81c7839f2be5c8a127e6c8e310b>>
*/
/**
@@ -339,6 +339,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool fixTextClippingAndroid15useBoundsForWidth();
/**
* Fix flex basis computation to not apply FitContent constraint in the main axis for non-measure container nodes, preventing unnecessary re-measurement in scroll containers.
*/
RN_EXPORT static bool fixYogaFlexBasisFitContentInMainAxis();
/**
* Enable system assertion validating that Fusebox is configured with a single host. When set, the CDP backend will dynamically disable features (Perf and Network) in the event that multiple hosts are registered (undefined behaviour), and broadcast this over `ReactNativeApplication.systemStateChanged`.
*/
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<803777ba8fd4207f5e466a546639a058>>
* @generated SignedSource<<f20eda0ee0b3b7494ccb9bb5b4f0d1b0>>
*/
/**
@@ -1109,6 +1109,24 @@ bool ReactNativeFeatureFlagsAccessor::fixTextClippingAndroid15useBoundsForWidth(
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::fixYogaFlexBasisFitContentInMainAxis() {
auto flagValue = fixYogaFlexBasisFitContentInMainAxis_.load();
if (!flagValue.has_value()) {
// This block is not exclusive but it is not necessary.
// If multiple threads try to initialize the feature flag, we would only
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(60, "fixYogaFlexBasisFitContentInMainAxis");
flagValue = currentProvider_->fixYogaFlexBasisFitContentInMainAxis();
fixYogaFlexBasisFitContentInMainAxis_ = flagValue;
}
return flagValue.value();
}
bool ReactNativeFeatureFlagsAccessor::fuseboxAssertSingleHostState() {
auto flagValue = fuseboxAssertSingleHostState_.load();
@@ -1118,7 +1136,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxAssertSingleHostState() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(60, "fuseboxAssertSingleHostState");
markFlagAsAccessed(61, "fuseboxAssertSingleHostState");
flagValue = currentProvider_->fuseboxAssertSingleHostState();
fuseboxAssertSingleHostState_ = flagValue;
@@ -1136,7 +1154,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxEnabledRelease() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(61, "fuseboxEnabledRelease");
markFlagAsAccessed(62, "fuseboxEnabledRelease");
flagValue = currentProvider_->fuseboxEnabledRelease();
fuseboxEnabledRelease_ = flagValue;
@@ -1154,7 +1172,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxFrameRecordingEnabled() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(62, "fuseboxFrameRecordingEnabled");
markFlagAsAccessed(63, "fuseboxFrameRecordingEnabled");
flagValue = currentProvider_->fuseboxFrameRecordingEnabled();
fuseboxFrameRecordingEnabled_ = flagValue;
@@ -1172,7 +1190,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxNetworkInspectionEnabled() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(63, "fuseboxNetworkInspectionEnabled");
markFlagAsAccessed(64, "fuseboxNetworkInspectionEnabled");
flagValue = currentProvider_->fuseboxNetworkInspectionEnabled();
fuseboxNetworkInspectionEnabled_ = flagValue;
@@ -1190,7 +1208,7 @@ bool ReactNativeFeatureFlagsAccessor::hideOffscreenVirtualViewsOnIOS() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(64, "hideOffscreenVirtualViewsOnIOS");
markFlagAsAccessed(65, "hideOffscreenVirtualViewsOnIOS");
flagValue = currentProvider_->hideOffscreenVirtualViewsOnIOS();
hideOffscreenVirtualViewsOnIOS_ = flagValue;
@@ -1208,7 +1226,7 @@ bool ReactNativeFeatureFlagsAccessor::overrideBySynchronousMountPropsAtMountingA
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(65, "overrideBySynchronousMountPropsAtMountingAndroid");
markFlagAsAccessed(66, "overrideBySynchronousMountPropsAtMountingAndroid");
flagValue = currentProvider_->overrideBySynchronousMountPropsAtMountingAndroid();
overrideBySynchronousMountPropsAtMountingAndroid_ = flagValue;
@@ -1226,7 +1244,7 @@ bool ReactNativeFeatureFlagsAccessor::perfIssuesEnabled() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(66, "perfIssuesEnabled");
markFlagAsAccessed(67, "perfIssuesEnabled");
flagValue = currentProvider_->perfIssuesEnabled();
perfIssuesEnabled_ = flagValue;
@@ -1244,7 +1262,7 @@ bool ReactNativeFeatureFlagsAccessor::perfMonitorV2Enabled() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(67, "perfMonitorV2Enabled");
markFlagAsAccessed(68, "perfMonitorV2Enabled");
flagValue = currentProvider_->perfMonitorV2Enabled();
perfMonitorV2Enabled_ = flagValue;
@@ -1262,7 +1280,7 @@ double ReactNativeFeatureFlagsAccessor::preparedTextCacheSize() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(68, "preparedTextCacheSize");
markFlagAsAccessed(69, "preparedTextCacheSize");
flagValue = currentProvider_->preparedTextCacheSize();
preparedTextCacheSize_ = flagValue;
@@ -1280,7 +1298,7 @@ bool ReactNativeFeatureFlagsAccessor::preventShadowTreeCommitExhaustion() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(69, "preventShadowTreeCommitExhaustion");
markFlagAsAccessed(70, "preventShadowTreeCommitExhaustion");
flagValue = currentProvider_->preventShadowTreeCommitExhaustion();
preventShadowTreeCommitExhaustion_ = flagValue;
@@ -1298,7 +1316,7 @@ bool ReactNativeFeatureFlagsAccessor::shouldPressibilityUseW3CPointerEventsForHo
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(70, "shouldPressibilityUseW3CPointerEventsForHover");
markFlagAsAccessed(71, "shouldPressibilityUseW3CPointerEventsForHover");
flagValue = currentProvider_->shouldPressibilityUseW3CPointerEventsForHover();
shouldPressibilityUseW3CPointerEventsForHover_ = flagValue;
@@ -1316,7 +1334,7 @@ bool ReactNativeFeatureFlagsAccessor::shouldTriggerResponderTransferOnScrollAndr
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(71, "shouldTriggerResponderTransferOnScrollAndroid");
markFlagAsAccessed(72, "shouldTriggerResponderTransferOnScrollAndroid");
flagValue = currentProvider_->shouldTriggerResponderTransferOnScrollAndroid();
shouldTriggerResponderTransferOnScrollAndroid_ = flagValue;
@@ -1334,7 +1352,7 @@ bool ReactNativeFeatureFlagsAccessor::skipActivityIdentityAssertionOnHostPause()
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(72, "skipActivityIdentityAssertionOnHostPause");
markFlagAsAccessed(73, "skipActivityIdentityAssertionOnHostPause");
flagValue = currentProvider_->skipActivityIdentityAssertionOnHostPause();
skipActivityIdentityAssertionOnHostPause_ = flagValue;
@@ -1352,7 +1370,7 @@ bool ReactNativeFeatureFlagsAccessor::syncAndroidClipToPaddingWithOverflow() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(73, "syncAndroidClipToPaddingWithOverflow");
markFlagAsAccessed(74, "syncAndroidClipToPaddingWithOverflow");
flagValue = currentProvider_->syncAndroidClipToPaddingWithOverflow();
syncAndroidClipToPaddingWithOverflow_ = flagValue;
@@ -1370,7 +1388,7 @@ bool ReactNativeFeatureFlagsAccessor::traceTurboModulePromiseRejectionsOnAndroid
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(74, "traceTurboModulePromiseRejectionsOnAndroid");
markFlagAsAccessed(75, "traceTurboModulePromiseRejectionsOnAndroid");
flagValue = currentProvider_->traceTurboModulePromiseRejectionsOnAndroid();
traceTurboModulePromiseRejectionsOnAndroid_ = flagValue;
@@ -1388,7 +1406,7 @@ bool ReactNativeFeatureFlagsAccessor::updateRuntimeShadowNodeReferencesOnCommit(
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(75, "updateRuntimeShadowNodeReferencesOnCommit");
markFlagAsAccessed(76, "updateRuntimeShadowNodeReferencesOnCommit");
flagValue = currentProvider_->updateRuntimeShadowNodeReferencesOnCommit();
updateRuntimeShadowNodeReferencesOnCommit_ = flagValue;
@@ -1406,7 +1424,7 @@ bool ReactNativeFeatureFlagsAccessor::updateRuntimeShadowNodeReferencesOnCommitT
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(76, "updateRuntimeShadowNodeReferencesOnCommitThread");
markFlagAsAccessed(77, "updateRuntimeShadowNodeReferencesOnCommitThread");
flagValue = currentProvider_->updateRuntimeShadowNodeReferencesOnCommitThread();
updateRuntimeShadowNodeReferencesOnCommitThread_ = flagValue;
@@ -1424,7 +1442,7 @@ bool ReactNativeFeatureFlagsAccessor::useAlwaysAvailableJSErrorHandling() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(77, "useAlwaysAvailableJSErrorHandling");
markFlagAsAccessed(78, "useAlwaysAvailableJSErrorHandling");
flagValue = currentProvider_->useAlwaysAvailableJSErrorHandling();
useAlwaysAvailableJSErrorHandling_ = flagValue;
@@ -1442,7 +1460,7 @@ bool ReactNativeFeatureFlagsAccessor::useFabricInterop() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(78, "useFabricInterop");
markFlagAsAccessed(79, "useFabricInterop");
flagValue = currentProvider_->useFabricInterop();
useFabricInterop_ = flagValue;
@@ -1460,7 +1478,7 @@ bool ReactNativeFeatureFlagsAccessor::useNativeViewConfigsInBridgelessMode() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(79, "useNativeViewConfigsInBridgelessMode");
markFlagAsAccessed(80, "useNativeViewConfigsInBridgelessMode");
flagValue = currentProvider_->useNativeViewConfigsInBridgelessMode();
useNativeViewConfigsInBridgelessMode_ = flagValue;
@@ -1478,7 +1496,7 @@ bool ReactNativeFeatureFlagsAccessor::useNestedScrollViewAndroid() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(80, "useNestedScrollViewAndroid");
markFlagAsAccessed(81, "useNestedScrollViewAndroid");
flagValue = currentProvider_->useNestedScrollViewAndroid();
useNestedScrollViewAndroid_ = flagValue;
@@ -1496,7 +1514,7 @@ bool ReactNativeFeatureFlagsAccessor::useSharedAnimatedBackend() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(81, "useSharedAnimatedBackend");
markFlagAsAccessed(82, "useSharedAnimatedBackend");
flagValue = currentProvider_->useSharedAnimatedBackend();
useSharedAnimatedBackend_ = flagValue;
@@ -1514,7 +1532,7 @@ bool ReactNativeFeatureFlagsAccessor::useTraitHiddenOnAndroid() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(82, "useTraitHiddenOnAndroid");
markFlagAsAccessed(83, "useTraitHiddenOnAndroid");
flagValue = currentProvider_->useTraitHiddenOnAndroid();
useTraitHiddenOnAndroid_ = flagValue;
@@ -1532,7 +1550,7 @@ bool ReactNativeFeatureFlagsAccessor::useTurboModuleInterop() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(83, "useTurboModuleInterop");
markFlagAsAccessed(84, "useTurboModuleInterop");
flagValue = currentProvider_->useTurboModuleInterop();
useTurboModuleInterop_ = flagValue;
@@ -1550,7 +1568,7 @@ bool ReactNativeFeatureFlagsAccessor::useTurboModules() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(84, "useTurboModules");
markFlagAsAccessed(85, "useTurboModules");
flagValue = currentProvider_->useTurboModules();
useTurboModules_ = flagValue;
@@ -1568,7 +1586,7 @@ bool ReactNativeFeatureFlagsAccessor::useUnorderedMapInDifferentiator() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(85, "useUnorderedMapInDifferentiator");
markFlagAsAccessed(86, "useUnorderedMapInDifferentiator");
flagValue = currentProvider_->useUnorderedMapInDifferentiator();
useUnorderedMapInDifferentiator_ = flagValue;
@@ -1586,7 +1604,7 @@ double ReactNativeFeatureFlagsAccessor::viewCullingOutsetRatio() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(86, "viewCullingOutsetRatio");
markFlagAsAccessed(87, "viewCullingOutsetRatio");
flagValue = currentProvider_->viewCullingOutsetRatio();
viewCullingOutsetRatio_ = flagValue;
@@ -1604,7 +1622,7 @@ bool ReactNativeFeatureFlagsAccessor::viewTransitionEnabled() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(87, "viewTransitionEnabled");
markFlagAsAccessed(88, "viewTransitionEnabled");
flagValue = currentProvider_->viewTransitionEnabled();
viewTransitionEnabled_ = flagValue;
@@ -1622,7 +1640,7 @@ double ReactNativeFeatureFlagsAccessor::virtualViewPrerenderRatio() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.
markFlagAsAccessed(88, "virtualViewPrerenderRatio");
markFlagAsAccessed(89, "virtualViewPrerenderRatio");
flagValue = currentProvider_->virtualViewPrerenderRatio();
virtualViewPrerenderRatio_ = flagValue;
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<1f2d789f0d84636a86e3cc194411cf3d>>
* @generated SignedSource<<06dba77b9b76d06d5c338ed8a97e33f5>>
*/
/**
@@ -92,6 +92,7 @@ class ReactNativeFeatureFlagsAccessor {
bool fixFindShadowNodeByTagRaceCondition();
bool fixMappingOfEventPrioritiesBetweenFabricAndReact();
bool fixTextClippingAndroid15useBoundsForWidth();
bool fixYogaFlexBasisFitContentInMainAxis();
bool fuseboxAssertSingleHostState();
bool fuseboxEnabledRelease();
bool fuseboxFrameRecordingEnabled();
@@ -132,7 +133,7 @@ class ReactNativeFeatureFlagsAccessor {
std::unique_ptr<ReactNativeFeatureFlagsProvider> currentProvider_;
bool wasOverridden_;
std::array<std::atomic<const char*>, 89> accessedFeatureFlags_;
std::array<std::atomic<const char*>, 90> accessedFeatureFlags_;
std::atomic<std::optional<bool>> commonTestFlag_;
std::atomic<std::optional<bool>> cdpInteractionMetricsEnabled_;
@@ -194,6 +195,7 @@ class ReactNativeFeatureFlagsAccessor {
std::atomic<std::optional<bool>> fixFindShadowNodeByTagRaceCondition_;
std::atomic<std::optional<bool>> fixMappingOfEventPrioritiesBetweenFabricAndReact_;
std::atomic<std::optional<bool>> fixTextClippingAndroid15useBoundsForWidth_;
std::atomic<std::optional<bool>> fixYogaFlexBasisFitContentInMainAxis_;
std::atomic<std::optional<bool>> fuseboxAssertSingleHostState_;
std::atomic<std::optional<bool>> fuseboxEnabledRelease_;
std::atomic<std::optional<bool>> fuseboxFrameRecordingEnabled_;
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<29c29b34ee3aefc5d904a1e26ed6f137>>
* @generated SignedSource<<0934d867533630904fc69e30e7a929b3>>
*/
/**
@@ -267,6 +267,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider {
return false;
}
bool fixYogaFlexBasisFitContentInMainAxis() override {
return false;
}
bool fuseboxAssertSingleHostState() override {
return true;
}
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<cbaba5f762ab27737ab468ff521c6685>>
* @generated SignedSource<<25d1f9cb509dbd8274e3a00237d2ea62>>
*/
/**
@@ -585,6 +585,15 @@ class ReactNativeFeatureFlagsDynamicProvider : public ReactNativeFeatureFlagsDef
return ReactNativeFeatureFlagsDefaults::fixTextClippingAndroid15useBoundsForWidth();
}
bool fixYogaFlexBasisFitContentInMainAxis() override {
auto value = values_["fixYogaFlexBasisFitContentInMainAxis"];
if (!value.isNull()) {
return value.getBool();
}
return ReactNativeFeatureFlagsDefaults::fixYogaFlexBasisFitContentInMainAxis();
}
bool fuseboxAssertSingleHostState() override {
auto value = values_["fuseboxAssertSingleHostState"];
if (!value.isNull()) {
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<bbe45a12ec0471479bd9763b59f1c3ca>>
* @generated SignedSource<<feb5aa86f9441652498d10e244717836>>
*/
/**
@@ -85,6 +85,7 @@ class ReactNativeFeatureFlagsProvider {
virtual bool fixFindShadowNodeByTagRaceCondition() = 0;
virtual bool fixMappingOfEventPrioritiesBetweenFabricAndReact() = 0;
virtual bool fixTextClippingAndroid15useBoundsForWidth() = 0;
virtual bool fixYogaFlexBasisFitContentInMainAxis() = 0;
virtual bool fuseboxAssertSingleHostState() = 0;
virtual bool fuseboxEnabledRelease() = 0;
virtual bool fuseboxFrameRecordingEnabled() = 0;
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<ce2fa6a5b28f4a59c63f92556b22eb99>>
* @generated SignedSource<<0b3534a570416860aa1ffc7e1d808090>>
*/
/**
@@ -344,6 +344,11 @@ bool NativeReactNativeFeatureFlags::fixTextClippingAndroid15useBoundsForWidth(
return ReactNativeFeatureFlags::fixTextClippingAndroid15useBoundsForWidth();
}
bool NativeReactNativeFeatureFlags::fixYogaFlexBasisFitContentInMainAxis(
jsi::Runtime& /*runtime*/) {
return ReactNativeFeatureFlags::fixYogaFlexBasisFitContentInMainAxis();
}
bool NativeReactNativeFeatureFlags::fuseboxAssertSingleHostState(
jsi::Runtime& /*runtime*/) {
return ReactNativeFeatureFlags::fuseboxAssertSingleHostState();
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<7db04fd2e9b9ea200fe1ef894ab33727>>
* @generated SignedSource<<0aeea7c4fa2a8aa4180c83bbd0746250>>
*/
/**
@@ -156,6 +156,8 @@ class NativeReactNativeFeatureFlags
bool fixTextClippingAndroid15useBoundsForWidth(jsi::Runtime& runtime);
bool fixYogaFlexBasisFitContentInMainAxis(jsi::Runtime& runtime);
bool fuseboxAssertSingleHostState(jsi::Runtime& runtime);
bool fuseboxEnabledRelease(jsi::Runtime& runtime);
@@ -899,6 +899,11 @@ yoga::Config& YogaLayoutableShadowNode::initializeYogaConfig(
YGConfigSetErrata(&config, YGConfigGetErrata(previousConfig));
}
if (ReactNativeFeatureFlags::fixYogaFlexBasisFitContentInMainAxis()) {
YGConfigSetExperimentalFeatureEnabled(
&config, YGExperimentalFeatureFixFlexBasisFitContent, true);
}
return config;
}
@@ -129,6 +129,8 @@ const char* YGExperimentalFeatureToString(const YGExperimentalFeature value) {
switch (value) {
case YGExperimentalFeatureWebFlexBasis:
return "web-flex-basis";
case YGExperimentalFeatureFixFlexBasisFitContent:
return "fix-flex-basis-fit-content";
}
return "unknown";
}
@@ -73,7 +73,8 @@ YG_DEFINE_ENUM_FLAG_OPERATORS(YGErrata)
YG_ENUM_DECL(
YGExperimentalFeature,
YGExperimentalFeatureWebFlexBasis)
YGExperimentalFeatureWebFlexBasis,
YGExperimentalFeatureFixFlexBasisFitContent)
YG_ENUM_DECL(
YGFlexDirection,
@@ -94,7 +94,18 @@ static void computeFlexBasisForChild(
const bool isColumnStyleDimDefined =
child->hasDefiniteLength(Dimension::Height, ownerHeight);
if (resolvedFlexBasis.isDefined() && yoga::isDefined(mainAxisSize)) {
const bool fixFlexBasisFitContent =
node->getConfig()->isExperimentalFeatureEnabled(
ExperimentalFeature::FixFlexBasisFitContent);
bool useResolvedFlexBasis =
resolvedFlexBasis.isDefined() && yoga::isDefined(mainAxisSize);
if (fixFlexBasisFitContent && resolvedFlexBasis.isDefined() &&
resolvedFlexBasis.unwrap() > 0) {
useResolvedFlexBasis = true;
}
if (useResolvedFlexBasis) {
if (child->getLayout().computedFlexBasis.isUndefined() ||
(child->getConfig()->isExperimentalFeatureEnabled(
ExperimentalFeature::WebFlexBasis) &&
@@ -164,12 +175,27 @@ static void computeFlexBasisForChild(
}
}
if ((isMainAxisRow && node->style().overflow() == Overflow::Scroll) ||
node->style().overflow() != Overflow::Scroll) {
if (yoga::isUndefined(childHeight) && yoga::isDefined(height)) {
childHeight = height;
childHeightSizingMode = SizingMode::FitContent;
}
// For height in the main axis (column direction): when the
// FixFlexBasisFitContent feature is enabled, skip FitContent for
// non-measure container children. This makes the flex basis independent
// of the parent's content-determined height, preventing unnecessary
// re-measurement cascades when a sibling changes size in a ScrollView.
//
// We only optimize the height (column) axis because text wrapping depends
// on width constraints propagating through container nodes. Removing
// FitContent from the width axis would cause text inside nested
// containers to stop wrapping.
bool applyHeightFitContent =
isMainAxisRow || node->style().overflow() != Overflow::Scroll;
if (fixFlexBasisFitContent) {
applyHeightFitContent = isMainAxisRow ||
(child->hasMeasureFunc() &&
node->style().overflow() != Overflow::Scroll);
}
if (applyHeightFitContent && yoga::isUndefined(childHeight) &&
yoga::isDefined(height)) {
childHeight = height;
childHeightSizingMode = SizingMode::FitContent;
}
const auto& childStyle = child->style();
@@ -537,6 +563,8 @@ static float computeFlexBasisForChildren(
yoga::Node* const node,
const float availableInnerWidth,
const float availableInnerHeight,
const float ownerWidth,
const float ownerHeight,
SizingMode widthSizingMode,
SizingMode heightSizingMode,
Direction direction,
@@ -598,8 +626,8 @@ static float computeFlexBasisForChildren(
availableInnerWidth,
widthSizingMode,
availableInnerHeight,
availableInnerWidth,
availableInnerHeight,
ownerWidth,
ownerHeight,
heightSizingMode,
direction,
layoutMarkerData,
@@ -1429,12 +1457,53 @@ static void calculateLayoutImpl(
// STEP 3: DETERMINE FLEX BASIS FOR EACH ITEM
// When this node is measured with MaxContent (FixFlexBasisFitContent
// behavior), availableInnerHeight is NaN.
// To preserve percentage resolution for descendants, derive a definite
// owner-size from the parent-provided ownerHeight.
float ownerWidthForChildren = availableInnerWidth;
float ownerHeightForChildren = availableInnerHeight;
if (node->getConfig()->isExperimentalFeatureEnabled(
ExperimentalFeature::FixFlexBasisFitContent)) {
const auto* owner = node->getOwner();
const bool isChildOfScrollContainer =
owner != nullptr && owner->style().overflow() == Overflow::Scroll;
if (!isChildOfScrollContainer) {
if (yoga::isUndefined(ownerWidthForChildren) &&
yoga::isDefined(ownerWidth)) {
ownerWidthForChildren = calculateAvailableInnerDimension(
node,
direction,
Dimension::Width,
ownerWidth - marginAxisRow,
paddingAndBorderAxisRow,
ownerWidth,
ownerWidth);
}
if (yoga::isUndefined(ownerHeightForChildren) &&
yoga::isDefined(ownerHeight)) {
ownerHeightForChildren = calculateAvailableInnerDimension(
node,
direction,
Dimension::Height,
ownerHeight - marginAxisColumn,
paddingAndBorderAxisColumn,
ownerHeight,
ownerWidth);
}
}
}
// Computed basis + margins + gap
float totalMainDim = 0;
totalMainDim += computeFlexBasisForChildren(
node,
availableInnerWidth,
availableInnerHeight,
ownerWidthForChildren,
ownerHeightForChildren,
widthSizingMode,
heightSizingMode,
direction,
@@ -17,11 +17,12 @@ namespace facebook::yoga {
enum class ExperimentalFeature : uint8_t {
WebFlexBasis = YGExperimentalFeatureWebFlexBasis,
FixFlexBasisFitContent = YGExperimentalFeatureFixFlexBasisFitContent,
};
template <>
constexpr int32_t ordinalCount<ExperimentalFeature>() {
return 1;
return 2;
}
constexpr ExperimentalFeature scopedEnum(YGExperimentalFeature unscoped) {
@@ -689,6 +689,17 @@ const definitions: FeatureFlagDefinitions = {
},
ossReleaseStage: 'experimental',
},
fixYogaFlexBasisFitContentInMainAxis: {
defaultValue: false,
metadata: {
dateAdded: '2026-03-09',
description:
'Fix flex basis computation to not apply FitContent constraint in the main axis for non-measure container nodes, preventing unnecessary re-measurement in scroll containers.',
expectedReleaseValue: true,
purpose: 'experimentation',
},
ossReleaseStage: 'none',
},
fuseboxAssertSingleHostState: {
defaultValue: true,
metadata: {
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @fantom_flags enableFabricCommitBranching:*
* @fantom_flags enableFabricCommitBranching:* fixYogaFlexBasisFitContentInMainAxis:*
* @flow strict-local
* @format
*/
@@ -15,6 +15,7 @@ import {createShadowNodeReferenceGetterRef} from '../ShadowNodeRevisionGetter';
import * as Fantom from '@react-native/fantom';
import * as React from 'react';
import {ScrollView, View} from 'react-native';
import * as ReactNativeFeatureFlags from 'react-native/src/private/featureflags/ReactNativeFeatureFlags';
test('base case when cloning results in revision +1', () => {
const root = Fantom.createRoot();
@@ -34,7 +35,7 @@ test('base case when cloning results in revision +1', () => {
expect(getRevision()).toBe(2);
});
test('changing height of the top item in ScrollView results in excessive cloning', () => {
test('changing height of sibling in ScrollView does not clone unrelated descendants', () => {
const root = Fantom.createRoot();
const [getRevision, ref] = createShadowNodeReferenceGetterRef();
@@ -70,6 +71,9 @@ test('changing height of the top item in ScrollView results in excessive cloning
);
});
// TODO(T225268793): the below assertion should be: `expect(getRevision()).toBe(1);`
expect(getRevision()).toBe(2);
if (ReactNativeFeatureFlags.fixYogaFlexBasisFitContentInMainAxis()) {
expect(getRevision()).toBe(1);
} else {
expect(getRevision()).toBe(2);
}
});
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<44a2abb1927d4db27052329f6544fefc>>
* @generated SignedSource<<5966ef11ee71a38059decda1c529fd6f>>
* @flow strict
* @noformat
*/
@@ -108,6 +108,7 @@ export type ReactNativeFeatureFlags = $ReadOnly<{
fixFindShadowNodeByTagRaceCondition: Getter<boolean>,
fixMappingOfEventPrioritiesBetweenFabricAndReact: Getter<boolean>,
fixTextClippingAndroid15useBoundsForWidth: Getter<boolean>,
fixYogaFlexBasisFitContentInMainAxis: Getter<boolean>,
fuseboxAssertSingleHostState: Getter<boolean>,
fuseboxEnabledRelease: Getter<boolean>,
fuseboxFrameRecordingEnabled: Getter<boolean>,
@@ -448,6 +449,10 @@ export const fixMappingOfEventPrioritiesBetweenFabricAndReact: Getter<boolean> =
* Fix text clipping starting in Android 15 due to usage of useBoundsForWidth
*/
export const fixTextClippingAndroid15useBoundsForWidth: Getter<boolean> = createNativeFlagGetter('fixTextClippingAndroid15useBoundsForWidth', false);
/**
* Fix flex basis computation to not apply FitContent constraint in the main axis for non-measure container nodes, preventing unnecessary re-measurement in scroll containers.
*/
export const fixYogaFlexBasisFitContentInMainAxis: Getter<boolean> = createNativeFlagGetter('fixYogaFlexBasisFitContentInMainAxis', false);
/**
* Enable system assertion validating that Fusebox is configured with a single host. When set, the CDP backend will dynamically disable features (Perf and Network) in the event that multiple hosts are registered (undefined behaviour), and broadcast this over `ReactNativeApplication.systemStateChanged`.
*/
@@ -4,7 +4,7 @@
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @generated SignedSource<<58c114ad13dad3296a563952cc6365f8>>
* @generated SignedSource<<85ddaee522fc3be8546aef21cf236e9a>>
* @flow strict
* @noformat
*/
@@ -85,6 +85,7 @@ export interface Spec extends TurboModule {
+fixFindShadowNodeByTagRaceCondition?: () => boolean;
+fixMappingOfEventPrioritiesBetweenFabricAndReact?: () => boolean;
+fixTextClippingAndroid15useBoundsForWidth?: () => boolean;
+fixYogaFlexBasisFitContentInMainAxis?: () => boolean;
+fuseboxAssertSingleHostState?: () => boolean;
+fuseboxEnabledRelease?: () => boolean;
+fuseboxFrameRecordingEnabled?: () => boolean;