Skip to content

Commit bb18409

Browse files
RSNarafacebook-github-bot
authored andcommitted
Introduce featureflag for safer RCTUnsafeExecuteOnMainQueueSync
Summary: Gating for "safer main queue sync dispatch": D74769326 Changelog: [Internal] Differential Revision: D74940621
1 parent 74b4033 commit bb18409

20 files changed

+157
-40
lines changed

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

+7-1
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<<e9a109fd77667dd0cb945ef6ef9737f2>>
7+
* @generated SignedSource<<24415ceea0dad0fec42af0b77ceec393>>
88
*/
99

1010
/**
@@ -198,6 +198,12 @@ public object ReactNativeFeatureFlags {
198198
@JvmStatic
199199
public fun enableResourceTimingAPI(): Boolean = accessor.enableResourceTimingAPI()
200200

201+
/**
202+
* Make RCTUnsafeExecuteOnMainQueueSync less likely to deadlock, when used in conjuction with sync rendering/events.
203+
*/
204+
@JvmStatic
205+
public fun enableSaferMainQueueSyncDispatchOnIOS(): Boolean = accessor.enableSaferMainQueueSyncDispatchOnIOS()
206+
201207
/**
202208
* Dispatches state updates synchronously in Fabric (e.g.: updates the scroll position in the shadow tree synchronously from the main thread).
203209
*/

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

+11-1
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<<1a5cd689229d4e0c31070123045e84da>>
7+
* @generated SignedSource<<07f351d4f8971f7bd7d2eb0115760565>>
88
*/
99

1010
/**
@@ -48,6 +48,7 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
4848
private var enablePreparedTextLayoutCache: Boolean? = null
4949
private var enablePropsUpdateReconciliationAndroidCache: Boolean? = null
5050
private var enableResourceTimingAPICache: Boolean? = null
51+
private var enableSaferMainQueueSyncDispatchOnIOSCache: Boolean? = null
5152
private var enableSynchronousStateUpdatesCache: Boolean? = null
5253
private var enableViewCullingCache: Boolean? = null
5354
private var enableViewRecyclingCache: Boolean? = null
@@ -321,6 +322,15 @@ internal class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAcces
321322
return cached
322323
}
323324

325+
override fun enableSaferMainQueueSyncDispatchOnIOS(): Boolean {
326+
var cached = enableSaferMainQueueSyncDispatchOnIOSCache
327+
if (cached == null) {
328+
cached = ReactNativeFeatureFlagsCxxInterop.enableSaferMainQueueSyncDispatchOnIOS()
329+
enableSaferMainQueueSyncDispatchOnIOSCache = cached
330+
}
331+
return cached
332+
}
333+
324334
override fun enableSynchronousStateUpdates(): Boolean {
325335
var cached = enableSynchronousStateUpdatesCache
326336
if (cached == null) {

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

+3-1
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<<c39d0c1834797b3309b4fc5ce814280c>>
7+
* @generated SignedSource<<db670241f820223af2783a44ca452d98>>
88
*/
99

1010
/**
@@ -84,6 +84,8 @@ public object ReactNativeFeatureFlagsCxxInterop {
8484

8585
@DoNotStrip @JvmStatic public external fun enableResourceTimingAPI(): Boolean
8686

87+
@DoNotStrip @JvmStatic public external fun enableSaferMainQueueSyncDispatchOnIOS(): Boolean
88+
8789
@DoNotStrip @JvmStatic public external fun enableSynchronousStateUpdates(): Boolean
8890

8991
@DoNotStrip @JvmStatic public external fun enableViewCulling(): Boolean

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

+3-1
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<<7f357475254104729cc7910c14e1c1fb>>
7+
* @generated SignedSource<<c7599024bfc8c04b5d53145d16a06c20>>
88
*/
99

1010
/**
@@ -79,6 +79,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi
7979

8080
override fun enableResourceTimingAPI(): Boolean = false
8181

82+
override fun enableSaferMainQueueSyncDispatchOnIOS(): Boolean = false
83+
8284
override fun enableSynchronousStateUpdates(): Boolean = false
8385

8486
override fun enableViewCulling(): Boolean = false

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

+12-1
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<<14cd1a58bd153dedda045a72c1494caa>>
7+
* @generated SignedSource<<52f72deb1601f741295b22caa9755749>>
88
*/
99

1010
/**
@@ -52,6 +52,7 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
5252
private var enablePreparedTextLayoutCache: Boolean? = null
5353
private var enablePropsUpdateReconciliationAndroidCache: Boolean? = null
5454
private var enableResourceTimingAPICache: Boolean? = null
55+
private var enableSaferMainQueueSyncDispatchOnIOSCache: Boolean? = null
5556
private var enableSynchronousStateUpdatesCache: Boolean? = null
5657
private var enableViewCullingCache: Boolean? = null
5758
private var enableViewRecyclingCache: Boolean? = null
@@ -353,6 +354,16 @@ internal class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcc
353354
return cached
354355
}
355356

357+
override fun enableSaferMainQueueSyncDispatchOnIOS(): Boolean {
358+
var cached = enableSaferMainQueueSyncDispatchOnIOSCache
359+
if (cached == null) {
360+
cached = currentProvider.enableSaferMainQueueSyncDispatchOnIOS()
361+
accessedFeatureFlags.add("enableSaferMainQueueSyncDispatchOnIOS")
362+
enableSaferMainQueueSyncDispatchOnIOSCache = cached
363+
}
364+
return cached
365+
}
366+
356367
override fun enableSynchronousStateUpdates(): Boolean {
357368
var cached = enableSynchronousStateUpdatesCache
358369
if (cached == null) {

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

+3-1
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<<593b1d64dc31038140032a6b0a439700>>
7+
* @generated SignedSource<<8c2ffe69841478213407e92e44519157>>
88
*/
99

1010
/**
@@ -79,6 +79,8 @@ public interface ReactNativeFeatureFlagsProvider {
7979

8080
@DoNotStrip public fun enableResourceTimingAPI(): Boolean
8181

82+
@DoNotStrip public fun enableSaferMainQueueSyncDispatchOnIOS(): Boolean
83+
8284
@DoNotStrip public fun enableSynchronousStateUpdates(): Boolean
8385

8486
@DoNotStrip public fun enableViewCulling(): Boolean

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

+15-1
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<<d74dc8182a14fddbd7118149298515bd>>
7+
* @generated SignedSource<<e197b252b246d3c777ce1850d365220e>>
88
*/
99

1010
/**
@@ -207,6 +207,12 @@ class ReactNativeFeatureFlagsJavaProvider
207207
return method(javaProvider_);
208208
}
209209

210+
bool enableSaferMainQueueSyncDispatchOnIOS() override {
211+
static const auto method =
212+
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableSaferMainQueueSyncDispatchOnIOS");
213+
return method(javaProvider_);
214+
}
215+
210216
bool enableSynchronousStateUpdates() override {
211217
static const auto method =
212218
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("enableSynchronousStateUpdates");
@@ -471,6 +477,11 @@ bool JReactNativeFeatureFlagsCxxInterop::enableResourceTimingAPI(
471477
return ReactNativeFeatureFlags::enableResourceTimingAPI();
472478
}
473479

480+
bool JReactNativeFeatureFlagsCxxInterop::enableSaferMainQueueSyncDispatchOnIOS(
481+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
482+
return ReactNativeFeatureFlags::enableSaferMainQueueSyncDispatchOnIOS();
483+
}
484+
474485
bool JReactNativeFeatureFlagsCxxInterop::enableSynchronousStateUpdates(
475486
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
476487
return ReactNativeFeatureFlags::enableSynchronousStateUpdates();
@@ -686,6 +697,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
686697
makeNativeMethod(
687698
"enableResourceTimingAPI",
688699
JReactNativeFeatureFlagsCxxInterop::enableResourceTimingAPI),
700+
makeNativeMethod(
701+
"enableSaferMainQueueSyncDispatchOnIOS",
702+
JReactNativeFeatureFlagsCxxInterop::enableSaferMainQueueSyncDispatchOnIOS),
689703
makeNativeMethod(
690704
"enableSynchronousStateUpdates",
691705
JReactNativeFeatureFlagsCxxInterop::enableSynchronousStateUpdates),

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

+4-1
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<<a5ab0022f6a01bd6e929d36d9d87db10>>
7+
* @generated SignedSource<<7f021510ca3f485b75e231d18cb58db9>>
88
*/
99

1010
/**
@@ -114,6 +114,9 @@ class JReactNativeFeatureFlagsCxxInterop
114114
static bool enableResourceTimingAPI(
115115
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
116116

117+
static bool enableSaferMainQueueSyncDispatchOnIOS(
118+
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
119+
117120
static bool enableSynchronousStateUpdates(
118121
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);
119122

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

+5-1
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<<88fdbea2f97f628187164a47a9737da0>>
7+
* @generated SignedSource<<997a6c9e018988ae1e4b7f02bad8f433>>
88
*/
99

1010
/**
@@ -138,6 +138,10 @@ bool ReactNativeFeatureFlags::enableResourceTimingAPI() {
138138
return getAccessor().enableResourceTimingAPI();
139139
}
140140

141+
bool ReactNativeFeatureFlags::enableSaferMainQueueSyncDispatchOnIOS() {
142+
return getAccessor().enableSaferMainQueueSyncDispatchOnIOS();
143+
}
144+
141145
bool ReactNativeFeatureFlags::enableSynchronousStateUpdates() {
142146
return getAccessor().enableSynchronousStateUpdates();
143147
}

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

+6-1
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<<a4123bc6f44835c022a1a5238908674c>>
7+
* @generated SignedSource<<b4febb028accc1620853ee78403a707a>>
88
*/
99

1010
/**
@@ -179,6 +179,11 @@ class ReactNativeFeatureFlags {
179179
*/
180180
RN_EXPORT static bool enableResourceTimingAPI();
181181

182+
/**
183+
* Make RCTUnsafeExecuteOnMainQueueSync less likely to deadlock, when used in conjuction with sync rendering/events.
184+
*/
185+
RN_EXPORT static bool enableSaferMainQueueSyncDispatchOnIOS();
186+
182187
/**
183188
* Dispatches state updates synchronously in Fabric (e.g.: updates the scroll position in the shadow tree synchronously from the main thread).
184189
*/

0 commit comments

Comments
 (0)