diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.kt index be9ac3869f6..06280a06524 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/StateWrapperImpl.kt @@ -14,8 +14,10 @@ import com.facebook.proguard.annotations.DoNotStripAny import com.facebook.react.bridge.NativeMap import com.facebook.react.bridge.ReadableNativeMap import com.facebook.react.bridge.WritableMap +import com.facebook.react.common.annotations.UnstableReactNativeAPI import com.facebook.react.common.mapbuffer.ReadableMapBuffer import com.facebook.react.uimanager.ReferenceStateWrapper +import com.facebook.react.uimanager.StateWrapper /** * This class holds reference to the C++ EventEmitter object. Instances of this class are created on @@ -23,6 +25,7 @@ import com.facebook.react.uimanager.ReferenceStateWrapper */ @SuppressLint("MissingNativeLoadLibrary") @DoNotStripAny +@OptIn(UnstableReactNativeAPI::class) internal class StateWrapperImpl private constructor() : HybridClassBase(), ReferenceStateWrapper { private external fun initHybrid() @@ -33,7 +36,7 @@ internal class StateWrapperImpl private constructor() : HybridClassBase(), Refer private external fun getStateDataReferenceImpl(): Any? - external fun updateStateImpl(map: NativeMap) + external fun updateStateImpl(map: NativeMap, updateMode: Int) override val stateDataMapBuffer: ReadableMapBuffer? get() { @@ -67,11 +70,15 @@ internal class StateWrapperImpl private constructor() : HybridClassBase(), Refer } override fun updateState(map: WritableMap) { + updateState(map, StateWrapper.UpdateMode.Asynchronous) + } + + override fun updateState(map: WritableMap, updateMode: StateWrapper.UpdateMode) { if (!isValid) { FLog.e(TAG, "Race between StateWrapperImpl destruction and updateState") return } - updateStateImpl(map as NativeMap) + updateStateImpl(map as NativeMap, updateMode.value) } override fun destroyState() { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.kt index c666bfd6f1b..e84af010bf4 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/fabric/mounting/MountItemDispatcher.kt @@ -58,6 +58,7 @@ internal class MountItemDispatcher( } private var inDispatch: Boolean = false + private var followUpDispatchRequired: Boolean = false var batchedExecutionTime: Long = 0L private set @@ -110,24 +111,29 @@ internal class MountItemDispatcher( @UiThread @ThreadConfined(UI) fun tryDispatchMountItems() { - // If we're already dispatching, don't reenter. - // Reentrance can potentially happen a lot on Android in Fabric because `updateState` from the - // mounting layer causes mount items to be dispatched synchronously. We want to 1) make sure we - // don't reenter in those cases, but 2) still execute those queued instructions synchronously. - // This is a pretty blunt tool, but we might not have better options since we really don't want - // to execute anything out-of-order. + // If we're already dispatching, don't reenter but signal that a follow-up dispatch is + // needed. This follows the same pattern as iOS's RCTMountingManager::initiateTransaction, + // which uses _followUpTransactionRequired flag to ensure mount items + // enqueued during dispatch (e.g., from synchronous state updates triggered by view layout) + // are processed in the same frame rather than deferred to the next one. if (inDispatch) { + if (ReactNativeFeatureFlags.enableFollowUpMountItemDispatchAndroid()) { + followUpDispatchRequired = true + } return } - inDispatch = true + do { + followUpDispatchRequired = false + inDispatch = true - try { - dispatchMountItems() - } finally { - // Clean up after running dispatchMountItems - even if an exception was thrown - inDispatch = false - } + try { + dispatchMountItems() + } finally { + // Clean up after running dispatchMountItems - even if an exception was thrown + inDispatch = false + } + } while (followUpDispatchRequired) // We call didDispatchMountItems regardless of whether we actually dispatched anything, since // NativeAnimatedModule relies on this for executing any animations that may have been diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt index 243a3eae3fa..c675838da59 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt @@ -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<> + * @generated SignedSource<> */ /** @@ -204,6 +204,12 @@ public object ReactNativeFeatureFlags { @JvmStatic public fun enableFlexboxAutoMinSizeInStrictMode(): Boolean = accessor.enableFlexboxAutoMinSizeInStrictMode() + /** + * When mount items are queued while MountItemDispatcher is already dispatching on Android (e.g. from a synchronous state update), dispatch them in the same frame instead of deferring them to the next one. + */ + @JvmStatic + public fun enableFollowUpMountItemDispatchAndroid(): Boolean = accessor.enableFollowUpMountItemDispatchAndroid() + /** * Enables font scale changes updating layout for measurable nodes. */ diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt index 0f110b75611..ac2da12670b 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt @@ -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<> + * @generated SignedSource<<846a8685f662d66dbcdaa4324c772d51>> */ /** @@ -49,6 +49,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces private var enableFabricCommitBranchingMergeOnMainThreadCache: Boolean? = null private var enableFabricLogsCache: Boolean? = null private var enableFlexboxAutoMinSizeInStrictModeCache: Boolean? = null + private var enableFollowUpMountItemDispatchAndroidCache: Boolean? = null private var enableFontScaleChangesUpdatingLayoutCache: Boolean? = null private var enableIOSCompressedTextFrameAdjustmentCache: Boolean? = null private var enableIOSTextBaselineOffsetPerLineCache: Boolean? = null @@ -378,6 +379,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces return cached } + override fun enableFollowUpMountItemDispatchAndroid(): Boolean { + var cached = enableFollowUpMountItemDispatchAndroidCache + if (cached == null) { + cached = ReactNativeFeatureFlagsCxxInterop.enableFollowUpMountItemDispatchAndroid() + enableFollowUpMountItemDispatchAndroidCache = cached + } + return cached + } + override fun enableFontScaleChangesUpdatingLayout(): Boolean { var cached = enableFontScaleChangesUpdatingLayoutCache if (cached == null) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt index fc4b23624bb..2a622658f4a 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt @@ -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<> + * @generated SignedSource<<9ccf3958e1db2db295ba73dc371b5185>> */ /** @@ -86,6 +86,8 @@ public object ReactNativeFeatureFlagsCxxInterop { @DoNotStrip @JvmStatic public external fun enableFlexboxAutoMinSizeInStrictMode(): Boolean + @DoNotStrip @JvmStatic public external fun enableFollowUpMountItemDispatchAndroid(): Boolean + @DoNotStrip @JvmStatic public external fun enableFontScaleChangesUpdatingLayout(): Boolean @DoNotStrip @JvmStatic public external fun enableIOSCompressedTextFrameAdjustment(): Boolean diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt index 380e9ec4c21..184ed3c5309 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt @@ -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<> + * @generated SignedSource<<0a04c5e0a0b418f2efd4b253646ae7c1>> */ /** @@ -81,6 +81,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi override fun enableFlexboxAutoMinSizeInStrictMode(): Boolean = false + override fun enableFollowUpMountItemDispatchAndroid(): Boolean = false + override fun enableFontScaleChangesUpdatingLayout(): Boolean = true override fun enableIOSCompressedTextFrameAdjustment(): Boolean = false diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt index 073cc2b90a7..4239667149d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt @@ -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<> + * @generated SignedSource<<861063ef7d217992d3cecd410e25d885>> */ /** @@ -53,6 +53,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc private var enableFabricCommitBranchingMergeOnMainThreadCache: Boolean? = null private var enableFabricLogsCache: Boolean? = null private var enableFlexboxAutoMinSizeInStrictModeCache: Boolean? = null + private var enableFollowUpMountItemDispatchAndroidCache: Boolean? = null private var enableFontScaleChangesUpdatingLayoutCache: Boolean? = null private var enableIOSCompressedTextFrameAdjustmentCache: Boolean? = null private var enableIOSTextBaselineOffsetPerLineCache: Boolean? = null @@ -411,6 +412,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc return cached } + override fun enableFollowUpMountItemDispatchAndroid(): Boolean { + var cached = enableFollowUpMountItemDispatchAndroidCache + if (cached == null) { + cached = currentProvider.enableFollowUpMountItemDispatchAndroid() + accessedFeatureFlags.add("enableFollowUpMountItemDispatchAndroid") + enableFollowUpMountItemDispatchAndroidCache = cached + } + return cached + } + override fun enableFontScaleChangesUpdatingLayout(): Boolean { var cached = enableFontScaleChangesUpdatingLayoutCache if (cached == null) { diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt index a639fd19fa5..1e53a20b61d 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt @@ -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<> + * @generated SignedSource<<5fa21c808df68be4c007469040fbca2a>> */ /** @@ -81,6 +81,8 @@ public interface ReactNativeFeatureFlagsProvider { @DoNotStrip public fun enableFlexboxAutoMinSizeInStrictMode(): Boolean + @DoNotStrip public fun enableFollowUpMountItemDispatchAndroid(): Boolean + @DoNotStrip public fun enableFontScaleChangesUpdatingLayout(): Boolean @DoNotStrip public fun enableIOSCompressedTextFrameAdjustment(): Boolean diff --git a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/StateWrapper.kt b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/StateWrapper.kt index 6e5d07abff3..d28921073df 100644 --- a/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/StateWrapper.kt +++ b/packages/react-native/ReactAndroid/src/main/java/com/facebook/react/uimanager/StateWrapper.kt @@ -9,6 +9,7 @@ package com.facebook.react.uimanager import com.facebook.react.bridge.ReadableNativeMap import com.facebook.react.bridge.WritableMap +import com.facebook.react.common.annotations.UnstableReactNativeAPI import com.facebook.react.common.mapbuffer.ReadableMapBuffer /** @@ -17,6 +18,15 @@ import com.facebook.react.common.mapbuffer.ReadableMapBuffer * by calling updateState, which communicates state back to the C++ layer. */ public interface StateWrapper { + /** + * Maps to EventQueue::UpdateMode in C++. Controls how state updates are flushed (Async or Sync). + */ + @UnstableReactNativeAPI + public enum class UpdateMode(public val value: Int) { + Asynchronous(0), + unstable_Immediate(1), + } + /** * Get a ReadableMapBuffer object from the C++ layer, which is a K/V map of short keys to values. * @@ -35,6 +45,12 @@ public interface StateWrapper { */ public fun updateState(map: WritableMap) + /** + * Pass a map of values back to the C++ layer. updateMode controls whether the update is queued + * asynchronously or flushed immediately. + */ + @UnstableReactNativeAPI public fun updateState(map: WritableMap, updateMode: UpdateMode) + /** * Mark state as unused and clean up in Java and in native. This should be called as early as * possible when you know a StateWrapper will no longer be used. If there's ANY chance of it being diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/StateWrapperImpl.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/StateWrapperImpl.cpp index 2459ad556d9..349780a367d 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/StateWrapperImpl.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/StateWrapperImpl.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -50,12 +51,13 @@ jni::local_ref StateWrapperImpl::getStateDataReferenceImpl() { return nullptr; } -void StateWrapperImpl::updateStateImpl(NativeMap* map) { +void StateWrapperImpl::updateStateImpl(NativeMap* map, jint updateMode) { if (state_) { // Get folly::dynamic from map auto dynamicMap = map->consume(); // Set state - state_->updateState(std::move(dynamicMap)); + state_->updateState( + std::move(dynamicMap), static_cast(updateMode)); } } diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/StateWrapperImpl.h b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/StateWrapperImpl.h index 39236a319d6..8c957177a39 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/fabric/StateWrapperImpl.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/fabric/StateWrapperImpl.h @@ -27,7 +27,7 @@ class StateWrapperImpl : public jni::HybridClass jni::local_ref getStateMapBufferDataImpl(); jni::local_ref getStateDataImpl(); jni::local_ref getStateDataReferenceImpl(); - void updateStateImpl(NativeMap *map); + void updateStateImpl(NativeMap *map, jint updateMode); void setState(std::shared_ptr state); std::shared_ptr getState() const; diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp index 882566ee95e..db6b559788e 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp @@ -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<<1ab2eec7b9c5bdd181ec5fbfd37149ab>> + * @generated SignedSource<<7e430d5b575ea983d53ecde87c4dc9f0>> */ /** @@ -213,6 +213,12 @@ class ReactNativeFeatureFlagsJavaProvider return method(javaProvider_); } + bool enableFollowUpMountItemDispatchAndroid() override { + static const auto method = + getReactNativeFeatureFlagsProviderJavaClass()->getMethod("enableFollowUpMountItemDispatchAndroid"); + return method(javaProvider_); + } + bool enableFontScaleChangesUpdatingLayout() override { static const auto method = getReactNativeFeatureFlagsProviderJavaClass()->getMethod("enableFontScaleChangesUpdatingLayout"); @@ -764,6 +770,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableFlexboxAutoMinSizeInStrictMode( return ReactNativeFeatureFlags::enableFlexboxAutoMinSizeInStrictMode(); } +bool JReactNativeFeatureFlagsCxxInterop::enableFollowUpMountItemDispatchAndroid( + facebook::jni::alias_ref /*unused*/) { + return ReactNativeFeatureFlags::enableFollowUpMountItemDispatchAndroid(); +} + bool JReactNativeFeatureFlagsCxxInterop::enableFontScaleChangesUpdatingLayout( facebook::jni::alias_ref /*unused*/) { return ReactNativeFeatureFlags::enableFontScaleChangesUpdatingLayout(); @@ -1217,6 +1228,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() { makeNativeMethod( "enableFlexboxAutoMinSizeInStrictMode", JReactNativeFeatureFlagsCxxInterop::enableFlexboxAutoMinSizeInStrictMode), + makeNativeMethod( + "enableFollowUpMountItemDispatchAndroid", + JReactNativeFeatureFlagsCxxInterop::enableFollowUpMountItemDispatchAndroid), makeNativeMethod( "enableFontScaleChangesUpdatingLayout", JReactNativeFeatureFlagsCxxInterop::enableFontScaleChangesUpdatingLayout), diff --git a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h index 8ae17b1dc3b..21b28bc24d4 100644 --- a/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h +++ b/packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h @@ -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<<2c8f9205f1de55591ede3845ba2fa877>> + * @generated SignedSource<<6b96c286c25d3c9fcb66d39d67092787>> */ /** @@ -117,6 +117,9 @@ class JReactNativeFeatureFlagsCxxInterop static bool enableFlexboxAutoMinSizeInStrictMode( facebook::jni::alias_ref); + static bool enableFollowUpMountItemDispatchAndroid( + facebook::jni::alias_ref); + static bool enableFontScaleChangesUpdatingLayout( facebook::jni::alias_ref); diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/mounting/MountItemDispatcherTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/mounting/MountItemDispatcherTest.kt new file mode 100644 index 00000000000..e0327690c41 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/fabric/mounting/MountItemDispatcherTest.kt @@ -0,0 +1,190 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.fabric.mounting + +import com.facebook.react.fabric.mounting.MountItemDispatcher.ItemDispatchListener +import com.facebook.react.fabric.mounting.mountitems.MountItem +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlags +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsDefaults +import com.facebook.react.internal.featureflags.ReactNativeFeatureFlagsForTests +import com.facebook.react.internal.tracing.PerformanceTracer +import com.facebook.react.uimanager.ViewManagerRegistry +import com.facebook.testutils.shadows.ShadowSoLoader +import org.assertj.core.api.Assertions.assertThat +import org.junit.Before +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner +import org.robolectric.annotation.Config +import org.robolectric.annotation.Implementation +import org.robolectric.annotation.Implements + +@RunWith(RobolectricTestRunner::class) +@Config(shadows = [ShadowSoLoader::class, MountItemDispatcherTest.ShadowPerformanceTracer::class]) +class MountItemDispatcherTest { + + private lateinit var dispatcher: MountItemDispatcher + private lateinit var dispatchListener: RecordingItemDispatchListener + + @Before + fun setUp() { + ReactNativeFeatureFlagsForTests.setUp() + val mountingManager = + MountingManager(ViewManagerRegistry(emptyList()), MountingManager.MountItemExecutor {}) + dispatchListener = RecordingItemDispatchListener() + dispatcher = MountItemDispatcher(mountingManager, dispatchListener) + } + + @Test + fun tryDispatchMountItems_executesQueuedMountItem() { + val item = RecordingMountItem() + + dispatcher.addMountItem(item) + dispatcher.tryDispatchMountItems() + + assertThat(item.executed).isTrue() + assertThat(dispatchListener.didDispatchCount).isEqualTo(1) + } + + /** + * Regression test for synchronous (`unstable_Immediate`) state updates on Android. When a mount + * item's execution synchronously updates shadow node state, it can enqueue new mount items and + * re-enter [MountItemDispatcher.tryDispatchMountItems] while a dispatch is already in progress. + * + * The re-entrant call must not drop those items: they should be flushed in the same dispatch + * pass, rather than being deferred to the next frame. + */ + @Test + fun tryDispatchMountItems_reentrantDispatch_executesFollowUpItemInSamePass() { + enableFollowUpMountItemDispatch() + val followUpItem = RecordingMountItem() + // Simulates a synchronous state update triggered while the first item is being mounted: it + // enqueues another mount item and re-enters the dispatcher. + val initialItem = + RecordingMountItem( + onExecute = { + dispatcher.addMountItem(followUpItem) + dispatcher.tryDispatchMountItems() + } + ) + + dispatcher.addMountItem(initialItem) + dispatcher.tryDispatchMountItems() + + assertThat(initialItem.executed).isTrue() + assertThat(followUpItem.executed).isTrue() + } + + @Test + fun tryDispatchMountItems_reentrantDispatch_preservesExecutionOrder() { + enableFollowUpMountItemDispatch() + val executionOrder = mutableListOf() + val followUpItem = RecordingMountItem(onExecute = { executionOrder.add("followUp") }) + val initialItem = + RecordingMountItem( + onExecute = { + executionOrder.add("initial") + dispatcher.addMountItem(followUpItem) + dispatcher.tryDispatchMountItems() + } + ) + + dispatcher.addMountItem(initialItem) + dispatcher.tryDispatchMountItems() + + assertThat(executionOrder).containsExactly("initial", "followUp") + } + + @Test + fun tryDispatchMountItems_reentrantDispatch_invokesDidDispatchOnceForOuterCall() { + enableFollowUpMountItemDispatch() + val initialItem = + RecordingMountItem( + onExecute = { + dispatcher.addMountItem(RecordingMountItem()) + dispatcher.tryDispatchMountItems() + } + ) + + dispatcher.addMountItem(initialItem) + dispatcher.tryDispatchMountItems() + + // The re-entrant call returns early and must not notify the listener; only the outer call does, + // once, after the follow-up loop has drained everything. + assertThat(dispatchListener.didDispatchCount).isEqualTo(1) + } + + @Test + fun tryDispatchMountItems_reentrantDispatch_withFlagDisabled_defersFollowUpItem() { + val followUpItem = RecordingMountItem() + val initialItem = + RecordingMountItem( + onExecute = { + dispatcher.addMountItem(followUpItem) + dispatcher.tryDispatchMountItems() + } + ) + + dispatcher.addMountItem(initialItem) + dispatcher.tryDispatchMountItems() + + assertThat(initialItem.executed).isTrue() + assertThat(followUpItem.executed).isFalse() + + dispatcher.tryDispatchMountItems() + + assertThat(followUpItem.executed).isTrue() + } + + private fun enableFollowUpMountItemDispatch() { + ReactNativeFeatureFlags.override( + object : ReactNativeFeatureFlagsDefaults() { + override fun enableFollowUpMountItemDispatchAndroid(): Boolean = true + }, + ) + } + + private class RecordingMountItem( + private val surfaceId: Int = 1, + private val onExecute: () -> Unit = {}, + ) : MountItem { + var executed: Boolean = false + private set + + override fun execute(mountingManager: MountingManager) { + executed = true + onExecute() + } + + override fun getSurfaceId(): Int = surfaceId + } + + private class RecordingItemDispatchListener : ItemDispatchListener { + var didDispatchCount: Int = 0 + private set + + override fun willMountItems(mountItems: List?) = Unit + + override fun didMountItems(mountItems: List?) = Unit + + override fun didDispatchMountItems() { + didDispatchCount++ + } + + override fun onItemsQueued() = Unit + } + + // isTracing() is a native method; its JNI library isn't loaded in JVM tests, so return false and + // let trace() just run its block. ShadowSoLoader covers the SoLoader.loadLibrary init. + @Implements(PerformanceTracer::class) + class ShadowPerformanceTracer { + companion object { + @JvmStatic @Implementation fun isTracing(): Boolean = false + } + } +} diff --git a/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/StateWrapperUpdateModeTest.kt b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/StateWrapperUpdateModeTest.kt new file mode 100644 index 00000000000..f3f12ff2de2 --- /dev/null +++ b/packages/react-native/ReactAndroid/src/test/java/com/facebook/react/uimanager/StateWrapperUpdateModeTest.kt @@ -0,0 +1,36 @@ +/* + * Copyright (c) Meta Platforms, Inc. and affiliates. + * + * This source code is licensed under the MIT license found in the + * LICENSE file in the root directory of this source tree. + */ + +package com.facebook.react.uimanager + +import com.facebook.react.common.annotations.UnstableReactNativeAPI +import com.facebook.react.uimanager.StateWrapper.UpdateMode +import org.assertj.core.api.Assertions.assertThat +import org.junit.Test +import org.junit.runner.RunWith +import org.robolectric.RobolectricTestRunner + +/** + * UpdateMode.value crosses JNI and is cast straight to C++ EventQueue::UpdateMode, so the values + * must match its order (Asynchronous = 0, unstable_Immediate = 1). A mismatch silently flips + * async/sync state updates. + */ +@OptIn(UnstableReactNativeAPI::class) +@RunWith(RobolectricTestRunner::class) +class StateWrapperUpdateModeTest { + + @Test + fun updateModeValues_matchCxxEventQueueUpdateMode() { + assertThat(UpdateMode.Asynchronous.value).isEqualTo(0) + assertThat(UpdateMode.unstable_Immediate.value).isEqualTo(1) + } + + @Test + fun updateModeValues_areDistinct() { + assertThat(UpdateMode.entries.map { it.value }).doesNotHaveDuplicates() + } +} diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp index c2457ce7afc..0399ade6a93 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp @@ -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<<7542508e6a3b0dd942557748186527b3>> + * @generated SignedSource<<493a51a28c2f55411c5c5aea374638d1>> */ /** @@ -142,6 +142,10 @@ bool ReactNativeFeatureFlags::enableFlexboxAutoMinSizeInStrictMode() { return getAccessor().enableFlexboxAutoMinSizeInStrictMode(); } +bool ReactNativeFeatureFlags::enableFollowUpMountItemDispatchAndroid() { + return getAccessor().enableFollowUpMountItemDispatchAndroid(); +} + bool ReactNativeFeatureFlags::enableFontScaleChangesUpdatingLayout() { return getAccessor().enableFontScaleChangesUpdatingLayout(); } diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h index 9668de64aae..aa7c277ed22 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h @@ -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<> + * @generated SignedSource<<2d7aa66f222fa01d4cc93c7d5ef2fdb7>> */ /** @@ -186,6 +186,11 @@ class ReactNativeFeatureFlags { */ RN_EXPORT static bool enableFlexboxAutoMinSizeInStrictMode(); + /** + * When mount items are queued while MountItemDispatcher is already dispatching on Android (e.g. from a synchronous state update), dispatch them in the same frame instead of deferring them to the next one. + */ + RN_EXPORT static bool enableFollowUpMountItemDispatchAndroid(); + /** * Enables font scale changes updating layout for measurable nodes. */ diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp index 418d452984b..88eda428135 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.cpp @@ -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<<3c7ff59afd1e9e05051e888b51a39ac0>> + * @generated SignedSource<<781830e6179bb655a1ba3d955c5d2a4a>> */ /** @@ -551,6 +551,24 @@ bool ReactNativeFeatureFlagsAccessor::enableFlexboxAutoMinSizeInStrictMode() { return flagValue.value(); } +bool ReactNativeFeatureFlagsAccessor::enableFollowUpMountItemDispatchAndroid() { + auto flagValue = enableFollowUpMountItemDispatchAndroid_.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(29, "enableFollowUpMountItemDispatchAndroid"); + + flagValue = currentProvider_->enableFollowUpMountItemDispatchAndroid(); + enableFollowUpMountItemDispatchAndroid_ = flagValue; + } + + return flagValue.value(); +} + bool ReactNativeFeatureFlagsAccessor::enableFontScaleChangesUpdatingLayout() { auto flagValue = enableFontScaleChangesUpdatingLayout_.load(); @@ -560,7 +578,7 @@ bool ReactNativeFeatureFlagsAccessor::enableFontScaleChangesUpdatingLayout() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(29, "enableFontScaleChangesUpdatingLayout"); + markFlagAsAccessed(30, "enableFontScaleChangesUpdatingLayout"); flagValue = currentProvider_->enableFontScaleChangesUpdatingLayout(); enableFontScaleChangesUpdatingLayout_ = flagValue; @@ -578,7 +596,7 @@ bool ReactNativeFeatureFlagsAccessor::enableIOSCompressedTextFrameAdjustment() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(30, "enableIOSCompressedTextFrameAdjustment"); + markFlagAsAccessed(31, "enableIOSCompressedTextFrameAdjustment"); flagValue = currentProvider_->enableIOSCompressedTextFrameAdjustment(); enableIOSCompressedTextFrameAdjustment_ = flagValue; @@ -596,7 +614,7 @@ bool ReactNativeFeatureFlagsAccessor::enableIOSTextBaselineOffsetPerLine() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(31, "enableIOSTextBaselineOffsetPerLine"); + markFlagAsAccessed(32, "enableIOSTextBaselineOffsetPerLine"); flagValue = currentProvider_->enableIOSTextBaselineOffsetPerLine(); enableIOSTextBaselineOffsetPerLine_ = flagValue; @@ -614,7 +632,7 @@ bool ReactNativeFeatureFlagsAccessor::enableIOSViewClipToPaddingBox() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(32, "enableIOSViewClipToPaddingBox"); + markFlagAsAccessed(33, "enableIOSViewClipToPaddingBox"); flagValue = currentProvider_->enableIOSViewClipToPaddingBox(); enableIOSViewClipToPaddingBox_ = flagValue; @@ -632,7 +650,7 @@ bool ReactNativeFeatureFlagsAccessor::enableImagePrefetchingAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(33, "enableImagePrefetchingAndroid"); + markFlagAsAccessed(34, "enableImagePrefetchingAndroid"); flagValue = currentProvider_->enableImagePrefetchingAndroid(); enableImagePrefetchingAndroid_ = flagValue; @@ -650,7 +668,7 @@ bool ReactNativeFeatureFlagsAccessor::enableImageTransparentTintColor() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(34, "enableImageTransparentTintColor"); + markFlagAsAccessed(35, "enableImageTransparentTintColor"); flagValue = currentProvider_->enableImageTransparentTintColor(); enableImageTransparentTintColor_ = flagValue; @@ -668,7 +686,7 @@ bool ReactNativeFeatureFlagsAccessor::enableImmediateUpdateModeForContentOffsetC // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(35, "enableImmediateUpdateModeForContentOffsetChanges"); + markFlagAsAccessed(36, "enableImmediateUpdateModeForContentOffsetChanges"); flagValue = currentProvider_->enableImmediateUpdateModeForContentOffsetChanges(); enableImmediateUpdateModeForContentOffsetChanges_ = flagValue; @@ -686,7 +704,7 @@ bool ReactNativeFeatureFlagsAccessor::enableImperativeEvents() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(36, "enableImperativeEvents"); + markFlagAsAccessed(37, "enableImperativeEvents"); flagValue = currentProvider_->enableImperativeEvents(); enableImperativeEvents_ = flagValue; @@ -704,7 +722,7 @@ bool ReactNativeFeatureFlagsAccessor::enableImperativeFocus() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(37, "enableImperativeFocus"); + markFlagAsAccessed(38, "enableImperativeFocus"); flagValue = currentProvider_->enableImperativeFocus(); enableImperativeFocus_ = flagValue; @@ -722,7 +740,7 @@ bool ReactNativeFeatureFlagsAccessor::enableInteropViewManagerClassLookUpOptimiz // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(38, "enableInteropViewManagerClassLookUpOptimizationIOS"); + markFlagAsAccessed(39, "enableInteropViewManagerClassLookUpOptimizationIOS"); flagValue = currentProvider_->enableInteropViewManagerClassLookUpOptimizationIOS(); enableInteropViewManagerClassLookUpOptimizationIOS_ = flagValue; @@ -740,7 +758,7 @@ bool ReactNativeFeatureFlagsAccessor::enableIntersectionObserverByDefault() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(39, "enableIntersectionObserverByDefault"); + markFlagAsAccessed(40, "enableIntersectionObserverByDefault"); flagValue = currentProvider_->enableIntersectionObserverByDefault(); enableIntersectionObserverByDefault_ = flagValue; @@ -758,7 +776,7 @@ bool ReactNativeFeatureFlagsAccessor::enableKeyEvents() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(40, "enableKeyEvents"); + markFlagAsAccessed(41, "enableKeyEvents"); flagValue = currentProvider_->enableKeyEvents(); enableKeyEvents_ = flagValue; @@ -776,7 +794,7 @@ bool ReactNativeFeatureFlagsAccessor::enableLayoutAnimationsOnAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(41, "enableLayoutAnimationsOnAndroid"); + markFlagAsAccessed(42, "enableLayoutAnimationsOnAndroid"); flagValue = currentProvider_->enableLayoutAnimationsOnAndroid(); enableLayoutAnimationsOnAndroid_ = flagValue; @@ -794,7 +812,7 @@ bool ReactNativeFeatureFlagsAccessor::enableLayoutAnimationsOnIOS() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(42, "enableLayoutAnimationsOnIOS"); + markFlagAsAccessed(43, "enableLayoutAnimationsOnIOS"); flagValue = currentProvider_->enableLayoutAnimationsOnIOS(); enableLayoutAnimationsOnIOS_ = flagValue; @@ -812,7 +830,7 @@ bool ReactNativeFeatureFlagsAccessor::enableModuleArgumentNSNullConversionIOS() // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(43, "enableModuleArgumentNSNullConversionIOS"); + markFlagAsAccessed(44, "enableModuleArgumentNSNullConversionIOS"); flagValue = currentProvider_->enableModuleArgumentNSNullConversionIOS(); enableModuleArgumentNSNullConversionIOS_ = flagValue; @@ -830,7 +848,7 @@ bool ReactNativeFeatureFlagsAccessor::enableMountingCoordinatorPullModelAndroid( // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(44, "enableMountingCoordinatorPullModelAndroid"); + markFlagAsAccessed(45, "enableMountingCoordinatorPullModelAndroid"); flagValue = currentProvider_->enableMountingCoordinatorPullModelAndroid(); enableMountingCoordinatorPullModelAndroid_ = flagValue; @@ -848,7 +866,7 @@ bool ReactNativeFeatureFlagsAccessor::enableMutationObserverByDefault() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(45, "enableMutationObserverByDefault"); + markFlagAsAccessed(46, "enableMutationObserverByDefault"); flagValue = currentProvider_->enableMutationObserverByDefault(); enableMutationObserverByDefault_ = flagValue; @@ -866,7 +884,7 @@ bool ReactNativeFeatureFlagsAccessor::enableNativeCSSParsing() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(46, "enableNativeCSSParsing"); + markFlagAsAccessed(47, "enableNativeCSSParsing"); flagValue = currentProvider_->enableNativeCSSParsing(); enableNativeCSSParsing_ = flagValue; @@ -884,7 +902,7 @@ bool ReactNativeFeatureFlagsAccessor::enablePreallocatedPropsDiffOnInsertAndroid // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(47, "enablePreallocatedPropsDiffOnInsertAndroid"); + markFlagAsAccessed(48, "enablePreallocatedPropsDiffOnInsertAndroid"); flagValue = currentProvider_->enablePreallocatedPropsDiffOnInsertAndroid(); enablePreallocatedPropsDiffOnInsertAndroid_ = flagValue; @@ -902,7 +920,7 @@ bool ReactNativeFeatureFlagsAccessor::enablePreparedTextLayout() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(48, "enablePreparedTextLayout"); + markFlagAsAccessed(49, "enablePreparedTextLayout"); flagValue = currentProvider_->enablePreparedTextLayout(); enablePreparedTextLayout_ = flagValue; @@ -920,7 +938,7 @@ bool ReactNativeFeatureFlagsAccessor::enablePropsUpdateReconciliationAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(49, "enablePropsUpdateReconciliationAndroid"); + markFlagAsAccessed(50, "enablePropsUpdateReconciliationAndroid"); flagValue = currentProvider_->enablePropsUpdateReconciliationAndroid(); enablePropsUpdateReconciliationAndroid_ = flagValue; @@ -938,7 +956,7 @@ bool ReactNativeFeatureFlagsAccessor::enableResizeObserverByDefault() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(50, "enableResizeObserverByDefault"); + markFlagAsAccessed(51, "enableResizeObserverByDefault"); flagValue = currentProvider_->enableResizeObserverByDefault(); enableResizeObserverByDefault_ = flagValue; @@ -956,7 +974,7 @@ bool ReactNativeFeatureFlagsAccessor::enableSwiftUIBasedFilters() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(51, "enableSwiftUIBasedFilters"); + markFlagAsAccessed(52, "enableSwiftUIBasedFilters"); flagValue = currentProvider_->enableSwiftUIBasedFilters(); enableSwiftUIBasedFilters_ = flagValue; @@ -974,7 +992,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewCulling() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(52, "enableViewCulling"); + markFlagAsAccessed(53, "enableViewCulling"); flagValue = currentProvider_->enableViewCulling(); enableViewCulling_ = flagValue; @@ -992,7 +1010,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewRecycling() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(53, "enableViewRecycling"); + markFlagAsAccessed(54, "enableViewRecycling"); flagValue = currentProvider_->enableViewRecycling(); enableViewRecycling_ = flagValue; @@ -1010,7 +1028,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewRecyclingForImage() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(54, "enableViewRecyclingForImage"); + markFlagAsAccessed(55, "enableViewRecyclingForImage"); flagValue = currentProvider_->enableViewRecyclingForImage(); enableViewRecyclingForImage_ = flagValue; @@ -1028,7 +1046,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewRecyclingForScrollView() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(55, "enableViewRecyclingForScrollView"); + markFlagAsAccessed(56, "enableViewRecyclingForScrollView"); flagValue = currentProvider_->enableViewRecyclingForScrollView(); enableViewRecyclingForScrollView_ = flagValue; @@ -1046,7 +1064,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewRecyclingForText() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(56, "enableViewRecyclingForText"); + markFlagAsAccessed(57, "enableViewRecyclingForText"); flagValue = currentProvider_->enableViewRecyclingForText(); enableViewRecyclingForText_ = flagValue; @@ -1064,7 +1082,7 @@ bool ReactNativeFeatureFlagsAccessor::enableViewRecyclingForView() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(57, "enableViewRecyclingForView"); + markFlagAsAccessed(58, "enableViewRecyclingForView"); flagValue = currentProvider_->enableViewRecyclingForView(); enableViewRecyclingForView_ = flagValue; @@ -1082,7 +1100,7 @@ bool ReactNativeFeatureFlagsAccessor::enableVirtualViewContainerStateExperimenta // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(58, "enableVirtualViewContainerStateExperimental"); + markFlagAsAccessed(59, "enableVirtualViewContainerStateExperimental"); flagValue = currentProvider_->enableVirtualViewContainerStateExperimental(); enableVirtualViewContainerStateExperimental_ = flagValue; @@ -1100,7 +1118,7 @@ bool ReactNativeFeatureFlagsAccessor::fixBorderlessRippleAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(59, "fixBorderlessRippleAndroid"); + markFlagAsAccessed(60, "fixBorderlessRippleAndroid"); flagValue = currentProvider_->fixBorderlessRippleAndroid(); fixBorderlessRippleAndroid_ = flagValue; @@ -1118,7 +1136,7 @@ bool ReactNativeFeatureFlagsAccessor::fixMappingOfEventPrioritiesBetweenFabricAn // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(60, "fixMappingOfEventPrioritiesBetweenFabricAndReact"); + markFlagAsAccessed(61, "fixMappingOfEventPrioritiesBetweenFabricAndReact"); flagValue = currentProvider_->fixMappingOfEventPrioritiesBetweenFabricAndReact(); fixMappingOfEventPrioritiesBetweenFabricAndReact_ = flagValue; @@ -1136,7 +1154,7 @@ bool ReactNativeFeatureFlagsAccessor::fixTextLayoutOnPixelDensityChange() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(61, "fixTextLayoutOnPixelDensityChange"); + markFlagAsAccessed(62, "fixTextLayoutOnPixelDensityChange"); flagValue = currentProvider_->fixTextLayoutOnPixelDensityChange(); fixTextLayoutOnPixelDensityChange_ = flagValue; @@ -1154,7 +1172,7 @@ bool ReactNativeFeatureFlagsAccessor::fixYogaFlexBasisFitContentInMainAxis() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(62, "fixYogaFlexBasisFitContentInMainAxis"); + markFlagAsAccessed(63, "fixYogaFlexBasisFitContentInMainAxis"); flagValue = currentProvider_->fixYogaFlexBasisFitContentInMainAxis(); fixYogaFlexBasisFitContentInMainAxis_ = flagValue; @@ -1172,7 +1190,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(63, "fuseboxAssertSingleHostState"); + markFlagAsAccessed(64, "fuseboxAssertSingleHostState"); flagValue = currentProvider_->fuseboxAssertSingleHostState(); fuseboxAssertSingleHostState_ = flagValue; @@ -1190,7 +1208,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(64, "fuseboxEnabledRelease"); + markFlagAsAccessed(65, "fuseboxEnabledRelease"); flagValue = currentProvider_->fuseboxEnabledRelease(); fuseboxEnabledRelease_ = flagValue; @@ -1208,7 +1226,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(65, "fuseboxFrameRecordingEnabled"); + markFlagAsAccessed(66, "fuseboxFrameRecordingEnabled"); flagValue = currentProvider_->fuseboxFrameRecordingEnabled(); fuseboxFrameRecordingEnabled_ = flagValue; @@ -1226,7 +1244,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxScreenshotCaptureEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(66, "fuseboxScreenshotCaptureEnabled"); + markFlagAsAccessed(67, "fuseboxScreenshotCaptureEnabled"); flagValue = currentProvider_->fuseboxScreenshotCaptureEnabled(); fuseboxScreenshotCaptureEnabled_ = flagValue; @@ -1244,7 +1262,7 @@ bool ReactNativeFeatureFlagsAccessor::fuseboxWebSocketEventsEnabled() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(67, "fuseboxWebSocketEventsEnabled"); + markFlagAsAccessed(68, "fuseboxWebSocketEventsEnabled"); flagValue = currentProvider_->fuseboxWebSocketEventsEnabled(); fuseboxWebSocketEventsEnabled_ = flagValue; @@ -1262,7 +1280,7 @@ bool ReactNativeFeatureFlagsAccessor::optimizedAnimatedPropUpdates() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(68, "optimizedAnimatedPropUpdates"); + markFlagAsAccessed(69, "optimizedAnimatedPropUpdates"); flagValue = currentProvider_->optimizedAnimatedPropUpdates(); optimizedAnimatedPropUpdates_ = flagValue; @@ -1280,7 +1298,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(69, "overrideBySynchronousMountPropsAtMountingAndroid"); + markFlagAsAccessed(70, "overrideBySynchronousMountPropsAtMountingAndroid"); flagValue = currentProvider_->overrideBySynchronousMountPropsAtMountingAndroid(); overrideBySynchronousMountPropsAtMountingAndroid_ = flagValue; @@ -1298,7 +1316,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(70, "perfIssuesEnabled"); + markFlagAsAccessed(71, "perfIssuesEnabled"); flagValue = currentProvider_->perfIssuesEnabled(); perfIssuesEnabled_ = flagValue; @@ -1316,7 +1334,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(71, "perfMonitorV2Enabled"); + markFlagAsAccessed(72, "perfMonitorV2Enabled"); flagValue = currentProvider_->perfMonitorV2Enabled(); perfMonitorV2Enabled_ = flagValue; @@ -1334,7 +1352,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(72, "preparedTextCacheSize"); + markFlagAsAccessed(73, "preparedTextCacheSize"); flagValue = currentProvider_->preparedTextCacheSize(); preparedTextCacheSize_ = flagValue; @@ -1352,7 +1370,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(73, "preventShadowTreeCommitExhaustion"); + markFlagAsAccessed(74, "preventShadowTreeCommitExhaustion"); flagValue = currentProvider_->preventShadowTreeCommitExhaustion(); preventShadowTreeCommitExhaustion_ = flagValue; @@ -1370,7 +1388,7 @@ bool ReactNativeFeatureFlagsAccessor::redBoxV2Android() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(74, "redBoxV2Android"); + markFlagAsAccessed(75, "redBoxV2Android"); flagValue = currentProvider_->redBoxV2Android(); redBoxV2Android_ = flagValue; @@ -1388,7 +1406,7 @@ bool ReactNativeFeatureFlagsAccessor::redBoxV2IOS() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(75, "redBoxV2IOS"); + markFlagAsAccessed(76, "redBoxV2IOS"); flagValue = currentProvider_->redBoxV2IOS(); redBoxV2IOS_ = flagValue; @@ -1406,7 +1424,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(76, "shouldPressibilityUseW3CPointerEventsForHover"); + markFlagAsAccessed(77, "shouldPressibilityUseW3CPointerEventsForHover"); flagValue = currentProvider_->shouldPressibilityUseW3CPointerEventsForHover(); shouldPressibilityUseW3CPointerEventsForHover_ = flagValue; @@ -1424,7 +1442,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(77, "shouldTriggerResponderTransferOnScrollAndroid"); + markFlagAsAccessed(78, "shouldTriggerResponderTransferOnScrollAndroid"); flagValue = currentProvider_->shouldTriggerResponderTransferOnScrollAndroid(); shouldTriggerResponderTransferOnScrollAndroid_ = flagValue; @@ -1442,7 +1460,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(78, "skipActivityIdentityAssertionOnHostPause"); + markFlagAsAccessed(79, "skipActivityIdentityAssertionOnHostPause"); flagValue = currentProvider_->skipActivityIdentityAssertionOnHostPause(); skipActivityIdentityAssertionOnHostPause_ = flagValue; @@ -1460,7 +1478,7 @@ bool ReactNativeFeatureFlagsAccessor::skipUnchangedChildrenInDifferentiator() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(79, "skipUnchangedChildrenInDifferentiator"); + markFlagAsAccessed(80, "skipUnchangedChildrenInDifferentiator"); flagValue = currentProvider_->skipUnchangedChildrenInDifferentiator(); skipUnchangedChildrenInDifferentiator_ = flagValue; @@ -1478,7 +1496,7 @@ bool ReactNativeFeatureFlagsAccessor::syncAndroidClipBoundsWithOverflow() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(80, "syncAndroidClipBoundsWithOverflow"); + markFlagAsAccessed(81, "syncAndroidClipBoundsWithOverflow"); flagValue = currentProvider_->syncAndroidClipBoundsWithOverflow(); syncAndroidClipBoundsWithOverflow_ = flagValue; @@ -1496,7 +1514,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(81, "traceTurboModulePromiseRejectionsOnAndroid"); + markFlagAsAccessed(82, "traceTurboModulePromiseRejectionsOnAndroid"); flagValue = currentProvider_->traceTurboModulePromiseRejectionsOnAndroid(); traceTurboModulePromiseRejectionsOnAndroid_ = flagValue; @@ -1514,7 +1532,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(82, "updateRuntimeShadowNodeReferencesOnCommit"); + markFlagAsAccessed(83, "updateRuntimeShadowNodeReferencesOnCommit"); flagValue = currentProvider_->updateRuntimeShadowNodeReferencesOnCommit(); updateRuntimeShadowNodeReferencesOnCommit_ = flagValue; @@ -1532,7 +1550,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(83, "updateRuntimeShadowNodeReferencesOnCommitThread"); + markFlagAsAccessed(84, "updateRuntimeShadowNodeReferencesOnCommitThread"); flagValue = currentProvider_->updateRuntimeShadowNodeReferencesOnCommitThread(); updateRuntimeShadowNodeReferencesOnCommitThread_ = flagValue; @@ -1550,7 +1568,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(84, "useAlwaysAvailableJSErrorHandling"); + markFlagAsAccessed(85, "useAlwaysAvailableJSErrorHandling"); flagValue = currentProvider_->useAlwaysAvailableJSErrorHandling(); useAlwaysAvailableJSErrorHandling_ = flagValue; @@ -1568,7 +1586,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(85, "useFabricInterop"); + markFlagAsAccessed(86, "useFabricInterop"); flagValue = currentProvider_->useFabricInterop(); useFabricInterop_ = flagValue; @@ -1586,7 +1604,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(86, "useNativeViewConfigsInBridgelessMode"); + markFlagAsAccessed(87, "useNativeViewConfigsInBridgelessMode"); flagValue = currentProvider_->useNativeViewConfigsInBridgelessMode(); useNativeViewConfigsInBridgelessMode_ = flagValue; @@ -1604,7 +1622,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(87, "useNestedScrollViewAndroid"); + markFlagAsAccessed(88, "useNestedScrollViewAndroid"); flagValue = currentProvider_->useNestedScrollViewAndroid(); useNestedScrollViewAndroid_ = flagValue; @@ -1622,7 +1640,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(88, "useSharedAnimatedBackend"); + markFlagAsAccessed(89, "useSharedAnimatedBackend"); flagValue = currentProvider_->useSharedAnimatedBackend(); useSharedAnimatedBackend_ = flagValue; @@ -1640,7 +1658,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(89, "useTraitHiddenOnAndroid"); + markFlagAsAccessed(90, "useTraitHiddenOnAndroid"); flagValue = currentProvider_->useTraitHiddenOnAndroid(); useTraitHiddenOnAndroid_ = flagValue; @@ -1658,7 +1676,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(90, "useTurboModuleInterop"); + markFlagAsAccessed(91, "useTurboModuleInterop"); flagValue = currentProvider_->useTurboModuleInterop(); useTurboModuleInterop_ = flagValue; @@ -1676,7 +1694,7 @@ bool ReactNativeFeatureFlagsAccessor::useWindowDensityForDisplayMetricsAndroid() // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(91, "useWindowDensityForDisplayMetricsAndroid"); + markFlagAsAccessed(92, "useWindowDensityForDisplayMetricsAndroid"); flagValue = currentProvider_->useWindowDensityForDisplayMetricsAndroid(); useWindowDensityForDisplayMetricsAndroid_ = flagValue; @@ -1694,7 +1712,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(92, "viewCullingOutsetRatio"); + markFlagAsAccessed(93, "viewCullingOutsetRatio"); flagValue = currentProvider_->viewCullingOutsetRatio(); viewCullingOutsetRatio_ = flagValue; @@ -1712,7 +1730,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(93, "viewTransitionEnabled"); + markFlagAsAccessed(94, "viewTransitionEnabled"); flagValue = currentProvider_->viewTransitionEnabled(); viewTransitionEnabled_ = flagValue; @@ -1730,7 +1748,7 @@ bool ReactNativeFeatureFlagsAccessor::viewTransitionUseHardwareBitmapAndroid() { // be accessing the provider multiple times but the end state of this // instance and the returned flag value would be the same. - markFlagAsAccessed(94, "viewTransitionUseHardwareBitmapAndroid"); + markFlagAsAccessed(95, "viewTransitionUseHardwareBitmapAndroid"); flagValue = currentProvider_->viewTransitionUseHardwareBitmapAndroid(); viewTransitionUseHardwareBitmapAndroid_ = flagValue; @@ -1748,7 +1766,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(95, "virtualViewPrerenderRatio"); + markFlagAsAccessed(96, "virtualViewPrerenderRatio"); flagValue = currentProvider_->virtualViewPrerenderRatio(); virtualViewPrerenderRatio_ = flagValue; diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h index a6ba9a46d70..ced722113f2 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsAccessor.h @@ -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<<0b7f6d7766d1e038b3909bb7ea634f83>> + * @generated SignedSource<<66130994f415fa235df5b77405d068ee>> */ /** @@ -63,6 +63,7 @@ class ReactNativeFeatureFlagsAccessor { bool enableFabricCommitBranchingMergeOnMainThread(); bool enableFabricLogs(); bool enableFlexboxAutoMinSizeInStrictMode(); + bool enableFollowUpMountItemDispatchAndroid(); bool enableFontScaleChangesUpdatingLayout(); bool enableIOSCompressedTextFrameAdjustment(); bool enableIOSTextBaselineOffsetPerLine(); @@ -141,7 +142,7 @@ class ReactNativeFeatureFlagsAccessor { std::unique_ptr currentProvider_; bool wasOverridden_; - std::array, 96> accessedFeatureFlags_; + std::array, 97> accessedFeatureFlags_; std::atomic> commonTestFlag_; std::atomic> cdpInteractionMetricsEnabled_; @@ -172,6 +173,7 @@ class ReactNativeFeatureFlagsAccessor { std::atomic> enableFabricCommitBranchingMergeOnMainThread_; std::atomic> enableFabricLogs_; std::atomic> enableFlexboxAutoMinSizeInStrictMode_; + std::atomic> enableFollowUpMountItemDispatchAndroid_; std::atomic> enableFontScaleChangesUpdatingLayout_; std::atomic> enableIOSCompressedTextFrameAdjustment_; std::atomic> enableIOSTextBaselineOffsetPerLine_; diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h index 76bb504681e..89bdc7100fe 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDefaults.h @@ -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<<46e48274f8b27b9c6136b13048682252>> + * @generated SignedSource<> */ /** @@ -145,6 +145,10 @@ class ReactNativeFeatureFlagsDefaults : public ReactNativeFeatureFlagsProvider { return false; } + bool enableFollowUpMountItemDispatchAndroid() override { + return false; + } + bool enableFontScaleChangesUpdatingLayout() override { return true; } diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h index bda4465a916..18d900df42e 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsDynamicProvider.h @@ -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<> + * @generated SignedSource<<41d72ef0a42994ab19ca76c16dc04a86>> */ /** @@ -308,6 +308,15 @@ class ReactNativeFeatureFlagsDynamicProvider : public ReactNativeFeatureFlagsDef return ReactNativeFeatureFlagsDefaults::enableFlexboxAutoMinSizeInStrictMode(); } + bool enableFollowUpMountItemDispatchAndroid() override { + auto value = values_["enableFollowUpMountItemDispatchAndroid"]; + if (!value.isNull()) { + return value.getBool(); + } + + return ReactNativeFeatureFlagsDefaults::enableFollowUpMountItemDispatchAndroid(); + } + bool enableFontScaleChangesUpdatingLayout() override { auto value = values_["enableFontScaleChangesUpdatingLayout"]; if (!value.isNull()) { diff --git a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h index bc1459bef44..20f0a085d43 100644 --- a/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h +++ b/packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlagsProvider.h @@ -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<<7626d25a1450564a30de026870f4d094>> + * @generated SignedSource<<96e9edf6ff0b347963cb155d59cb1005>> */ /** @@ -56,6 +56,7 @@ class ReactNativeFeatureFlagsProvider { virtual bool enableFabricCommitBranchingMergeOnMainThread() = 0; virtual bool enableFabricLogs() = 0; virtual bool enableFlexboxAutoMinSizeInStrictMode() = 0; + virtual bool enableFollowUpMountItemDispatchAndroid() = 0; virtual bool enableFontScaleChangesUpdatingLayout() = 0; virtual bool enableIOSCompressedTextFrameAdjustment() = 0; virtual bool enableIOSTextBaselineOffsetPerLine() = 0; diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp index 9d8c414b268..83eec6acd78 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.cpp @@ -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<> + * @generated SignedSource<> */ /** @@ -189,6 +189,11 @@ bool NativeReactNativeFeatureFlags::enableFlexboxAutoMinSizeInStrictMode( return ReactNativeFeatureFlags::enableFlexboxAutoMinSizeInStrictMode(); } +bool NativeReactNativeFeatureFlags::enableFollowUpMountItemDispatchAndroid( + jsi::Runtime& /*runtime*/) { + return ReactNativeFeatureFlags::enableFollowUpMountItemDispatchAndroid(); +} + bool NativeReactNativeFeatureFlags::enableFontScaleChangesUpdatingLayout( jsi::Runtime& /*runtime*/) { return ReactNativeFeatureFlags::enableFontScaleChangesUpdatingLayout(); diff --git a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h index 4014c7ac655..493206eca62 100644 --- a/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h +++ b/packages/react-native/ReactCommon/react/nativemodule/featureflags/NativeReactNativeFeatureFlags.h @@ -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<<4d3151d0ce9a022c5b9b74e2a910229d>> + * @generated SignedSource<<3f0c67926f9bc7a9973e17afe59b3ec9>> */ /** @@ -96,6 +96,8 @@ class NativeReactNativeFeatureFlags bool enableFlexboxAutoMinSizeInStrictMode(jsi::Runtime& runtime); + bool enableFollowUpMountItemDispatchAndroid(jsi::Runtime& runtime); + bool enableFontScaleChangesUpdatingLayout(jsi::Runtime& runtime); bool enableIOSCompressedTextFrameAdjustment(jsi::Runtime& runtime); diff --git a/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h b/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h index f115b358b70..7a39f6ff91c 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h +++ b/packages/react-native/ReactCommon/react/renderer/core/ConcreteState.h @@ -117,9 +117,10 @@ class ConcreteState : public State { return getData().getDynamic(); } - void updateState(folly::dynamic &&data) const override + void updateState(folly::dynamic &&data, EventQueue::UpdateMode updateMode = EventQueue::UpdateMode::Asynchronous) + const override { - updateState(Data(getData(), std::move(data))); + updateState(Data(getData(), std::move(data)), updateMode); } MapBuffer getMapBuffer() const override diff --git a/packages/react-native/ReactCommon/react/renderer/core/State.h b/packages/react-native/ReactCommon/react/renderer/core/State.h index 7a07bc26806..ee681f73876 100644 --- a/packages/react-native/ReactCommon/react/renderer/core/State.h +++ b/packages/react-native/ReactCommon/react/renderer/core/State.h @@ -13,6 +13,7 @@ #include #include #include +#include #endif #include @@ -68,7 +69,9 @@ class State { virtual folly::dynamic getDynamic() const = 0; virtual MapBuffer getMapBuffer() const = 0; virtual jni::local_ref getJNIReference() const = 0; - virtual void updateState(folly::dynamic &&data) const = 0; + virtual void updateState( + folly::dynamic &&data, + EventQueue::UpdateMode updateMode = EventQueue::UpdateMode::Asynchronous) const = 0; #endif protected: diff --git a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js index ac6c41e0a8e..a2757e6007e 100644 --- a/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js +++ b/packages/react-native/scripts/featureflags/ReactNativeFeatureFlags.config.js @@ -363,6 +363,17 @@ const definitions: FeatureFlagDefinitions = { }, ossReleaseStage: 'experimental', }, + enableFollowUpMountItemDispatchAndroid: { + defaultValue: false, + metadata: { + dateAdded: '2026-09-29', + description: + 'When mount items are queued while MountItemDispatcher is already dispatching on Android (e.g. from a synchronous state update), dispatch them in the same frame instead of deferring them to the next one.', + expectedReleaseValue: true, + purpose: 'experimentation', + }, + ossReleaseStage: 'none', + }, enableFontScaleChangesUpdatingLayout: { defaultValue: true, metadata: { diff --git a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js index c1c6f65c21d..237cf99f874 100644 --- a/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/ReactNativeFeatureFlags.js @@ -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<<5a79107fda7ef89a1d68594cad01b8e7>> + * @generated SignedSource<<73327eab3ccc39c8d823c9d2b110d23c>> * @flow strict * @noformat */ @@ -78,6 +78,7 @@ export type ReactNativeFeatureFlags = Readonly<{ enableFabricCommitBranchingMergeOnMainThread: Getter, enableFabricLogs: Getter, enableFlexboxAutoMinSizeInStrictMode: Getter, + enableFollowUpMountItemDispatchAndroid: Getter, enableFontScaleChangesUpdatingLayout: Getter, enableIOSCompressedTextFrameAdjustment: Getter, enableIOSTextBaselineOffsetPerLine: Getter, @@ -337,6 +338,10 @@ export const enableFabricLogs: Getter = createNativeFlagGetter('enableF * Enables CSS Flexbox ยง4.5 automatic minimum sizing under strict layout conformance. When enabled, a flex item with an undefined main-axis `min-width`/`min-height` under strict conformance receives a content-derived minimum size (per spec) instead of an undefined (0) minimum. Defaults off so the behaviour can be ramped independently of strict conformance. */ export const enableFlexboxAutoMinSizeInStrictMode: Getter = createNativeFlagGetter('enableFlexboxAutoMinSizeInStrictMode', false); +/** + * When mount items are queued while MountItemDispatcher is already dispatching on Android (e.g. from a synchronous state update), dispatch them in the same frame instead of deferring them to the next one. + */ +export const enableFollowUpMountItemDispatchAndroid: Getter = createNativeFlagGetter('enableFollowUpMountItemDispatchAndroid', false); /** * Enables font scale changes updating layout for measurable nodes. */ diff --git a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js index 48355705857..65dd1af1c1b 100644 --- a/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js +++ b/packages/react-native/src/private/featureflags/specs/NativeReactNativeFeatureFlags.js @@ -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<> + * @generated SignedSource<<043ccaebbb88ea3c413809d9d628d584>> * @flow strict * @noformat */ @@ -54,6 +54,7 @@ export interface Spec extends TurboModule { readonly enableFabricCommitBranchingMergeOnMainThread?: () => boolean; readonly enableFabricLogs?: () => boolean; readonly enableFlexboxAutoMinSizeInStrictMode?: () => boolean; + readonly enableFollowUpMountItemDispatchAndroid?: () => boolean; readonly enableFontScaleChangesUpdatingLayout?: () => boolean; readonly enableIOSCompressedTextFrameAdjustment?: () => boolean; readonly enableIOSTextBaselineOffsetPerLine?: () => boolean; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api index 333251a9a6e..6d9ac1caa78 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidDebugCxx.api @@ -2343,7 +2343,7 @@ class facebook::react::State { public virtual facebook::react::MapBuffer getMapBuffer() const = 0; public virtual folly::dynamic getDynamic() const = 0; public virtual jni::local_ref getJNIReference() const = 0; - public virtual void updateState(folly::dynamic&& data) const = 0; + public virtual void updateState(folly::dynamic&& data, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const = 0; public virtual ~State() = default; } @@ -2367,7 +2367,7 @@ class facebook::react::StateWrapperImpl : public jni::HybridClass getState() const; public void setState(std::shared_ptr state); - public void updateStateImpl(facebook::react::NativeMap* map); + public void updateStateImpl(facebook::react::NativeMap* map, jint updateMode); } class facebook::react::SurfaceHandlerBinding : public jni::HybridClass { @@ -3818,7 +3818,7 @@ class facebook::react::ConcreteState : public facebook::react::State { public virtual facebook::react::MapBuffer getMapBuffer() const override; public virtual folly::dynamic getDynamic() const override; public virtual jni::local_ref getJNIReference() const override; - public virtual void updateState(folly::dynamic&& data) const override; + public virtual void updateState(folly::dynamic&& data, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const override; public void updateState(facebook::react::ConcreteState::Data&& newData, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const; public void updateState(std::function callback, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const; public ~ConcreteState() override = default; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api index 15895518dad..d2b41ea569c 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidFrameworksCxx.api @@ -3781,7 +3781,7 @@ class facebook::react::State { public virtual facebook::react::MapBuffer getMapBuffer() const = 0; public virtual folly::dynamic getDynamic() const = 0; public virtual jni::local_ref getJNIReference() const = 0; - public virtual void updateState(folly::dynamic&& data) const = 0; + public virtual void updateState(folly::dynamic&& data, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const = 0; public virtual ~State() = default; } @@ -3805,7 +3805,7 @@ class facebook::react::StateWrapperImpl : public jni::HybridClass getState() const; public void setState(std::shared_ptr state); - public void updateStateImpl(facebook::react::NativeMap* map); + public void updateStateImpl(facebook::react::NativeMap* map, jint updateMode); } class facebook::react::SurfaceHandler { @@ -6913,7 +6913,7 @@ class facebook::react::ConcreteState : public facebook::react::State { public virtual facebook::react::MapBuffer getMapBuffer() const override; public virtual folly::dynamic getDynamic() const override; public virtual jni::local_ref getJNIReference() const override; - public virtual void updateState(folly::dynamic&& data) const override; + public virtual void updateState(folly::dynamic&& data, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const override; public void updateState(facebook::react::ConcreteState::Data&& newData, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const; public void updateState(std::function callback, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const; public ~ConcreteState() override = default; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api index b700de9a234..57f7bc09831 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidNewarchCxx.api @@ -2336,7 +2336,7 @@ class facebook::react::State { public virtual facebook::react::MapBuffer getMapBuffer() const = 0; public virtual folly::dynamic getDynamic() const = 0; public virtual jni::local_ref getJNIReference() const = 0; - public virtual void updateState(folly::dynamic&& data) const = 0; + public virtual void updateState(folly::dynamic&& data, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const = 0; public virtual ~State() = default; } @@ -2360,7 +2360,7 @@ class facebook::react::StateWrapperImpl : public jni::HybridClass getState() const; public void setState(std::shared_ptr state); - public void updateStateImpl(facebook::react::NativeMap* map); + public void updateStateImpl(facebook::react::NativeMap* map, jint updateMode); } class facebook::react::SurfaceHandlerBinding : public jni::HybridClass { @@ -3811,7 +3811,7 @@ class facebook::react::ConcreteState : public facebook::react::State { public virtual facebook::react::MapBuffer getMapBuffer() const override; public virtual folly::dynamic getDynamic() const override; public virtual jni::local_ref getJNIReference() const override; - public virtual void updateState(folly::dynamic&& data) const override; + public virtual void updateState(folly::dynamic&& data, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const override; public void updateState(facebook::react::ConcreteState::Data&& newData, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const; public void updateState(std::function callback, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const; public ~ConcreteState() override = default; diff --git a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api index b700de9a234..57f7bc09831 100644 --- a/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api +++ b/scripts/cxx-api/api-snapshots/ReactAndroidReleaseCxx.api @@ -2336,7 +2336,7 @@ class facebook::react::State { public virtual facebook::react::MapBuffer getMapBuffer() const = 0; public virtual folly::dynamic getDynamic() const = 0; public virtual jni::local_ref getJNIReference() const = 0; - public virtual void updateState(folly::dynamic&& data) const = 0; + public virtual void updateState(folly::dynamic&& data, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const = 0; public virtual ~State() = default; } @@ -2360,7 +2360,7 @@ class facebook::react::StateWrapperImpl : public jni::HybridClass getState() const; public void setState(std::shared_ptr state); - public void updateStateImpl(facebook::react::NativeMap* map); + public void updateStateImpl(facebook::react::NativeMap* map, jint updateMode); } class facebook::react::SurfaceHandlerBinding : public jni::HybridClass { @@ -3811,7 +3811,7 @@ class facebook::react::ConcreteState : public facebook::react::State { public virtual facebook::react::MapBuffer getMapBuffer() const override; public virtual folly::dynamic getDynamic() const override; public virtual jni::local_ref getJNIReference() const override; - public virtual void updateState(folly::dynamic&& data) const override; + public virtual void updateState(folly::dynamic&& data, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const override; public void updateState(facebook::react::ConcreteState::Data&& newData, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const; public void updateState(std::function callback, facebook::react::EventQueue::UpdateMode updateMode = facebook::react::EventQueue::UpdateMode::Asynchronous) const; public ~ConcreteState() override = default;