Skip to content

Commit 404f323

Browse files
rubennortefacebook-github-bot
authored andcommitted
Set up experiment to fix the mapping of event priorities between Fabric and React (facebook#45013)
Summary: Pull Request resolved: facebook#45013 Changelog: [internal] ## Context We recently realized that in the majority of events dispatched to React from Fabric, passive effects were being mounted synchronously, blocking paint instead of in a separate task after paint. The reason for that is that in React, passive effects for discrete events are mounted synchronously by design (see reactwg/react-18#128), and Fabric is currently assigning the discrete event priority to most current events (including things like layout events). ## Changes This creates a feature flag to opt into a more granular control over event priorities in React Native. Instead of assigning the discrete event priority to events by default, this would assign the "default" event priority by default, except for events dispatched during continuous events that would also be considered continuous. This would also fix the priority for continuous events, that it was currently being assigned as "default" incorrectly. Reviewed By: christophpurrer, javache, sammy-SC Differential Revision: D58677191 fbshipit-source-id: c65a8dc2118ed028e1e895adec54f9072b7e55a6
1 parent 43d69ee commit 404f323

20 files changed

+168
-43
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlags.kt

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<177f05d7b2fadcfffa32cb5a7a21c76b>>
7+
* @generated SignedSource<<9a33a6bc10cdb2b0f9fcb15805a06982>>
88
*/
99

1010
/**
@@ -94,6 +94,12 @@ public object ReactNativeFeatureFlags {
9494
@JvmStatic
9595
public fun enableUIConsistency(): Boolean = accessor.enableUIConsistency()
9696

97+
/**
98+
* Uses the default event priority instead of the discreet event priority by default when dispatching events from Fabric to React.
99+
*/
100+
@JvmStatic
101+
public fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean = accessor.fixMappingOfEventPrioritiesBetweenFabricAndReact()
102+
97103
/**
98104
* Fixes a leak in SurfaceMountingManager.mRemoveDeleteTreeUIFrameCallback
99105
*/

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxAccessor.kt

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<492902f307361b8f7b7d42973561a3b4>>
7+
* @generated SignedSource<<5d67280406c16b01ba71b7b75e814a79>>
88
*/
99

1010
/**
@@ -31,6 +31,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
3131
private var enableMicrotasksCache: Boolean? = null
3232
private var enableSynchronousStateUpdatesCache: Boolean? = null
3333
private var enableUIConsistencyCache: Boolean? = null
34+
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
3435
private var fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeakCache: Boolean? = null
3536
private var forceBatchingMountItemsOnAndroidCache: Boolean? = null
3637
private var fuseboxEnabledDebugCache: Boolean? = null
@@ -144,6 +145,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
144145
return cached
145146
}
146147

148+
override fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean {
149+
var cached = fixMappingOfEventPrioritiesBetweenFabricAndReactCache
150+
if (cached == null) {
151+
cached = ReactNativeFeatureFlagsCxxInterop.fixMappingOfEventPrioritiesBetweenFabricAndReact()
152+
fixMappingOfEventPrioritiesBetweenFabricAndReactCache = cached
153+
}
154+
return cached
155+
}
156+
147157
override fun fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak(): Boolean {
148158
var cached = fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeakCache
149159
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsCxxInterop.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<05bf91e1b2a64cdc48615137deec627a>>
7+
* @generated SignedSource<<154baea748cdf7b8e05a1e4448053673>>
88
*/
99

1010
/**
@@ -50,6 +50,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
5050

5151
@DoNotStrip @JvmStatic public external fun enableUIConsistency(): Boolean
5252

53+
@DoNotStrip @JvmStatic public external fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean
54+
5355
@DoNotStrip @JvmStatic public external fun fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak(): Boolean
5456

5557
@DoNotStrip @JvmStatic public external fun forceBatchingMountItemsOnAndroid(): Boolean

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsDefaults.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<7c95ebf976344317cd8904d71ea22fe5>>
7+
* @generated SignedSource<<34bbd584a612fa88cc6adf2d2bc51b92>>
88
*/
99

1010
/**
@@ -45,6 +45,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
4545

4646
override fun enableUIConsistency(): Boolean = false
4747

48+
override fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean = false
49+
4850
override fun fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak(): Boolean = false
4951

5052
override fun forceBatchingMountItemsOnAndroid(): Boolean = false

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsLocalAccessor.kt

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<d23d2a5f44f2b2068dde9e85e5b1ce9f>>
7+
* @generated SignedSource<<d991cac9311ee91e5e9401b143b69145>>
88
*/
99

1010
/**
@@ -35,6 +35,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
3535
private var enableMicrotasksCache: Boolean? = null
3636
private var enableSynchronousStateUpdatesCache: Boolean? = null
3737
private var enableUIConsistencyCache: Boolean? = null
38+
private var fixMappingOfEventPrioritiesBetweenFabricAndReactCache: Boolean? = null
3839
private var fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeakCache: Boolean? = null
3940
private var forceBatchingMountItemsOnAndroidCache: Boolean? = null
4041
private var fuseboxEnabledDebugCache: Boolean? = null
@@ -159,6 +160,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
159160
return cached
160161
}
161162

163+
override fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean {
164+
var cached = fixMappingOfEventPrioritiesBetweenFabricAndReactCache
165+
if (cached == null) {
166+
cached = currentProvider.fixMappingOfEventPrioritiesBetweenFabricAndReact()
167+
accessedFeatureFlags.add("fixMappingOfEventPrioritiesBetweenFabricAndReact")
168+
fixMappingOfEventPrioritiesBetweenFabricAndReactCache = cached
169+
}
170+
return cached
171+
}
172+
162173
override fun fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak(): Boolean {
163174
var cached = fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeakCache
164175
if (cached == null) {

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/internal/featureflags/ReactNativeFeatureFlagsProvider.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<d84816a13ad49b6e1c69c968a8503385>>
7+
* @generated SignedSource<<aae9b8936680c1cd6db2c1c0135e1cef>>
88
*/
99

1010
/**
@@ -45,6 +45,8 @@ public interface ReactNativeFeatureFlagsProvider {
4545

4646
@DoNotStrip public fun enableUIConsistency(): Boolean
4747

48+
@DoNotStrip public fun fixMappingOfEventPrioritiesBetweenFabricAndReact(): Boolean
49+
4850
@DoNotStrip public fun fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak(): Boolean
4951

5052
@DoNotStrip public fun forceBatchingMountItemsOnAndroid(): Boolean

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<2af7a8ae4860f81b46e48afb17ee54b6>>
7+
* @generated SignedSource<<88f5b83b8a3d7902eaab333246b59ed3>>
88
*/
99

1010
/**
@@ -105,6 +105,12 @@ class ReactNativeFeatureFlagsProviderHolder
105105
return method(javaProvider_);
106106
}
107107

108+
bool fixMappingOfEventPrioritiesBetweenFabricAndReact() override {
109+
static const auto method =
110+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("fixMappingOfEventPrioritiesBetweenFabricAndReact");
111+
return method(javaProvider_);
112+
}
113+
108114
bool fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak() override {
109115
static const auto method =
110116
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak");
@@ -242,6 +248,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableUIConsistency(
242248
return ReactNativeFeatureFlags::enableUIConsistency();
243249
}
244250

251+
bool JReactNativeFeatureFlagsCxxInterop::fixMappingOfEventPrioritiesBetweenFabricAndReact(
252+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
253+
return ReactNativeFeatureFlags::fixMappingOfEventPrioritiesBetweenFabricAndReact();
254+
}
255+
245256
bool JReactNativeFeatureFlagsCxxInterop::fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak(
246257
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
247258
return ReactNativeFeatureFlags::fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak();
@@ -357,6 +368,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
357368
makeNativeMethod(
358369
"enableUIConsistency",
359370
JReactNativeFeatureFlagsCxxInterop::enableUIConsistency),
371+
makeNativeMethod(
372+
"fixMappingOfEventPrioritiesBetweenFabricAndReact",
373+
JReactNativeFeatureFlagsCxxInterop::fixMappingOfEventPrioritiesBetweenFabricAndReact),
360374
makeNativeMethod(
361375
"fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak",
362376
JReactNativeFeatureFlagsCxxInterop::fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak),

packages/react-native/ReactAndroid/src/main/jni/react/featureflags/JReactNativeFeatureFlagsCxxInterop.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<1d1422d073ae40ee4bbc788dc222cc28>>
7+
* @generated SignedSource<<66b47850d8e211f78b3e3dd40b6cc37e>>
88
*/
99

1010
/**
@@ -63,6 +63,9 @@ class JReactNativeFeatureFlagsCxxInterop
6363
static bool enableUIConsistency(
6464
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
6565

66+
static bool fixMappingOfEventPrioritiesBetweenFabricAndReact(
67+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
68+
6669
static bool fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak(
6770
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
6871

packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<ec12fd62d1dc2109e52a95094d7ad167>>
7+
* @generated SignedSource<<dd5872a21f84a41bea247e137541ddfc>>
88
*/
99

1010
/**
@@ -65,6 +65,10 @@ bool ReactNativeFeatureFlags::enableUIConsistency() {
6565
return getAccessor().enableUIConsistency();
6666
}
6767

68+
bool ReactNativeFeatureFlags::fixMappingOfEventPrioritiesBetweenFabricAndReact() {
69+
return getAccessor().fixMappingOfEventPrioritiesBetweenFabricAndReact();
70+
}
71+
6872
bool ReactNativeFeatureFlags::fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak() {
6973
return getAccessor().fixStoppedSurfaceRemoveDeleteTreeUIFrameCallbackLeak();
7074
}

packages/react-native/ReactCommon/react/featureflags/ReactNativeFeatureFlags.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* This source code is licensed under the MIT license found in the
55
* LICENSE file in the root directory of this source tree.
66
*
7-
* @generated SignedSource<<5f1ae3edfe01ee0545bd89137c5cb3e9>>
7+
* @generated SignedSource<<e45c35dee2c9e2135995ccf2c8a6def3>>
88
*/
99

1010
/**
@@ -92,6 +92,11 @@ class ReactNativeFeatureFlags {
9292
*/
9393
RN_EXPORT static bool enableUIConsistency();
9494

95+
/**
96+
* Uses the default event priority instead of the discreet event priority by default when dispatching events from Fabric to React.
97+
*/
98+
RN_EXPORT static bool fixMappingOfEventPrioritiesBetweenFabricAndReact();
99+
95100
/**
96101
* Fixes a leak in SurfaceMountingManager.mRemoveDeleteTreeUIFrameCallback
97102
*/

0 commit comments

Comments
 (0)