Skip to content

Commit

Permalink
Migrate traceTurboModulePromiseRejections to ReactNativeFeatureFlags
Browse files Browse the repository at this point in the history
Summary:
Migrate traceTurboModulePromiseRejections to ReactNativeFeatureFlags

changelog: [internal] internal

Differential Revision: D60124027
  • Loading branch information
mdvacca committed Jul 24, 2024
1 parent 84590d6 commit 992e4a1
Show file tree
Hide file tree
Showing 23 changed files with 133 additions and 53 deletions.
1 change: 0 additions & 1 deletion packages/react-native/ReactAndroid/api/ReactAndroid.api
Original file line number Diff line number Diff line change
Expand Up @@ -1966,7 +1966,6 @@ public class com/facebook/react/config/ReactFeatureFlags {
public static field enableBridgelessArchitecture Z
public static field enableFabricRenderer Z
public static field enableViewRecycling Z
public static field traceTurboModulePromiseRejections Z
public static field unstable_useFabricInterop Z
public static field unstable_useTurboModuleInterop Z
public static field useTurboModules Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

import com.facebook.infer.annotation.Nullsafe;
import com.facebook.proguard.annotations.DoNotStripAny;
import com.facebook.react.common.build.ReactBuildConfig;

/**
* Hi there, traveller! This configuration class is not meant to be used by end-users of RN. It
Expand Down Expand Up @@ -58,10 +57,4 @@ public class ReactFeatureFlags {
* Feature Flag to enable View Recycling. When enabled, individual ViewManagers must still opt-in.
*/
public static boolean enableViewRecycling = false;

/**
* Enables storing js caller stack when creating promise in native module. This is useful in case
* of Promise rejection and tracing the cause.
*/
public static boolean traceTurboModulePromiseRejections = ReactBuildConfig.DEBUG;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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<<7da3cb6f175655f0995854fec4e2bdc0>>
* @generated SignedSource<<5c7964726373a75fab5d6473bf7d6390>>
*/

/**
Expand Down Expand Up @@ -220,6 +220,12 @@ public object ReactNativeFeatureFlags {
@JvmStatic
public fun setAndroidLayoutDirection(): Boolean = accessor.setAndroidLayoutDirection()

/**
* Enables storing js caller stack when creating promise in native module. This is useful in case of Promise rejection and tracing the cause.
*/
@JvmStatic
public fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean = accessor.traceTurboModulePromiseRejectionsOnAndroid()

/**
* By default, native module methods that return void run asynchronously. This flag will make execution of void methods in TurboModules stay on the JS thread.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<1a716665793debf1d360c43666a26bf4>>
* @generated SignedSource<<c0a9c3de094bf2c9d580b8d79e5de47b>>
*/

/**
Expand Down Expand Up @@ -52,6 +52,7 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
private var lazyAnimationCallbacksCache: Boolean? = null
private var loadVectorDrawablesOnImagesCache: Boolean? = null
private var setAndroidLayoutDirectionCache: Boolean? = null
private var traceTurboModulePromiseRejectionsOnAndroidCache: Boolean? = null
private var unstable_enableTurboModuleSyncVoidMethodsCache: Boolean? = null
private var useImmediateExecutorInAndroidBridgelessCache: Boolean? = null
private var useModernRuntimeSchedulerCache: Boolean? = null
Expand Down Expand Up @@ -350,6 +351,15 @@ public class ReactNativeFeatureFlagsCxxAccessor : ReactNativeFeatureFlagsAccesso
return cached
}

override fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean {
var cached = traceTurboModulePromiseRejectionsOnAndroidCache
if (cached == null) {
cached = ReactNativeFeatureFlagsCxxInterop.traceTurboModulePromiseRejectionsOnAndroid()
traceTurboModulePromiseRejectionsOnAndroidCache = cached
}
return cached
}

override fun unstable_enableTurboModuleSyncVoidMethods(): Boolean {
var cached = unstable_enableTurboModuleSyncVoidMethodsCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<c3bc009f093106875e5901c796a279b6>>
* @generated SignedSource<<3837dde4571d8da810192d1a6ed9931f>>
*/

/**
Expand Down Expand Up @@ -92,6 +92,8 @@ public object ReactNativeFeatureFlagsCxxInterop {

@DoNotStrip @JvmStatic public external fun setAndroidLayoutDirection(): Boolean

@DoNotStrip @JvmStatic public external fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean

@DoNotStrip @JvmStatic public external fun unstable_enableTurboModuleSyncVoidMethods(): Boolean

@DoNotStrip @JvmStatic public external fun useImmediateExecutorInAndroidBridgeless(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<58f9cbca5bde7a1c69bfcdc2b0371fac>>
* @generated SignedSource<<aa3b1f6e52ccb44cc90e2096a7bdcf91>>
*/

/**
Expand Down Expand Up @@ -87,6 +87,8 @@ public open class ReactNativeFeatureFlagsDefaults : ReactNativeFeatureFlagsProvi

override fun setAndroidLayoutDirection(): Boolean = true

override fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean = false

override fun unstable_enableTurboModuleSyncVoidMethods(): Boolean = false

override fun useImmediateExecutorInAndroidBridgeless(): Boolean = false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<612f1c90153b6e51af016bdff9f0d686>>
* @generated SignedSource<<ac064cdc77d4375aa34118b1607de52f>>
*/

/**
Expand Down Expand Up @@ -56,6 +56,7 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
private var lazyAnimationCallbacksCache: Boolean? = null
private var loadVectorDrawablesOnImagesCache: Boolean? = null
private var setAndroidLayoutDirectionCache: Boolean? = null
private var traceTurboModulePromiseRejectionsOnAndroidCache: Boolean? = null
private var unstable_enableTurboModuleSyncVoidMethodsCache: Boolean? = null
private var useImmediateExecutorInAndroidBridgelessCache: Boolean? = null
private var useModernRuntimeSchedulerCache: Boolean? = null
Expand Down Expand Up @@ -386,6 +387,16 @@ public class ReactNativeFeatureFlagsLocalAccessor : ReactNativeFeatureFlagsAcces
return cached
}

override fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean {
var cached = traceTurboModulePromiseRejectionsOnAndroidCache
if (cached == null) {
cached = currentProvider.traceTurboModulePromiseRejectionsOnAndroid()
accessedFeatureFlags.add("traceTurboModulePromiseRejectionsOnAndroid")
traceTurboModulePromiseRejectionsOnAndroidCache = cached
}
return cached
}

override fun unstable_enableTurboModuleSyncVoidMethods(): Boolean {
var cached = unstable_enableTurboModuleSyncVoidMethodsCache
if (cached == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<447365b8d9668f096ce8536006ce4fce>>
* @generated SignedSource<<ac9f91956cff38f56bd2b984b4288c57>>
*/

/**
Expand Down Expand Up @@ -87,6 +87,8 @@ public interface ReactNativeFeatureFlagsProvider {

@DoNotStrip public fun setAndroidLayoutDirection(): Boolean

@DoNotStrip public fun traceTurboModulePromiseRejectionsOnAndroid(): Boolean

@DoNotStrip public fun unstable_enableTurboModuleSyncVoidMethods(): Boolean

@DoNotStrip public fun useImmediateExecutorInAndroidBridgeless(): Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<3e16d4c3f7cf9ea3003f1d8795e48012>>
* @generated SignedSource<<1fa4fea1bd8055330de591d6ee315b12>>
*/

/**
Expand Down Expand Up @@ -231,6 +231,12 @@ class ReactNativeFeatureFlagsProviderHolder
return method(javaProvider_);
}

bool traceTurboModulePromiseRejectionsOnAndroid() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("traceTurboModulePromiseRejectionsOnAndroid");
return method(javaProvider_);
}

bool unstable_enableTurboModuleSyncVoidMethods() override {
static const auto method =
getReactNativeFeatureFlagsProviderJavaClass()->getMethod<jboolean()>("unstable_enableTurboModuleSyncVoidMethods");
Expand Down Expand Up @@ -449,6 +455,11 @@ bool JReactNativeFeatureFlagsCxxInterop::setAndroidLayoutDirection(
return ReactNativeFeatureFlags::setAndroidLayoutDirection();
}

bool JReactNativeFeatureFlagsCxxInterop::traceTurboModulePromiseRejectionsOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::traceTurboModulePromiseRejectionsOnAndroid();
}

bool JReactNativeFeatureFlagsCxxInterop::unstable_enableTurboModuleSyncVoidMethods(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop> /*unused*/) {
return ReactNativeFeatureFlags::unstable_enableTurboModuleSyncVoidMethods();
Expand Down Expand Up @@ -607,6 +618,9 @@ void JReactNativeFeatureFlagsCxxInterop::registerNatives() {
makeNativeMethod(
"setAndroidLayoutDirection",
JReactNativeFeatureFlagsCxxInterop::setAndroidLayoutDirection),
makeNativeMethod(
"traceTurboModulePromiseRejectionsOnAndroid",
JReactNativeFeatureFlagsCxxInterop::traceTurboModulePromiseRejectionsOnAndroid),
makeNativeMethod(
"unstable_enableTurboModuleSyncVoidMethods",
JReactNativeFeatureFlagsCxxInterop::unstable_enableTurboModuleSyncVoidMethods),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<70480406412a57da0477e1ef9f0ccb65>>
* @generated SignedSource<<e0cbf15721fa34aab83adb41580517ab>>
*/

/**
Expand Down Expand Up @@ -126,6 +126,9 @@ class JReactNativeFeatureFlagsCxxInterop
static bool setAndroidLayoutDirection(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool traceTurboModulePromiseRejectionsOnAndroid(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

static bool unstable_enableTurboModuleSyncVoidMethods(
facebook::jni::alias_ref<JReactNativeFeatureFlagsCxxInterop>);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<75a955f9378acf4e962712aa92dfbc56>>
* @generated SignedSource<<fc990d89982314febeb85bf3ebc2d6f5>>
*/

/**
Expand Down Expand Up @@ -149,6 +149,10 @@ bool ReactNativeFeatureFlags::setAndroidLayoutDirection() {
return getAccessor().setAndroidLayoutDirection();
}

bool ReactNativeFeatureFlags::traceTurboModulePromiseRejectionsOnAndroid() {
return getAccessor().traceTurboModulePromiseRejectionsOnAndroid();
}

bool ReactNativeFeatureFlags::unstable_enableTurboModuleSyncVoidMethods() {
return getAccessor().unstable_enableTurboModuleSyncVoidMethods();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<5d54c5495ab58db2782b031cf15120fd>>
* @generated SignedSource<<bd744fbaf219b4ca7e8825c5767d9c68>>
*/

/**
Expand Down Expand Up @@ -197,6 +197,11 @@ class ReactNativeFeatureFlags {
*/
RN_EXPORT static bool setAndroidLayoutDirection();

/**
* Enables storing js caller stack when creating promise in native module. This is useful in case of Promise rejection and tracing the cause.
*/
RN_EXPORT static bool traceTurboModulePromiseRejectionsOnAndroid();

/**
* By default, native module methods that return void run asynchronously. This flag will make execution of void methods in TurboModules stay on the JS thread.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<<c6da9cd1afbd0a63aa5d4f16b9f65193>>
* @generated SignedSource<<259fdc29e31d60640467883cb486dd95>>
*/

/**
Expand Down Expand Up @@ -605,6 +605,24 @@ bool ReactNativeFeatureFlagsAccessor::setAndroidLayoutDirection() {
return flagValue.value();
}

bool ReactNativeFeatureFlagsAccessor::traceTurboModulePromiseRejectionsOnAndroid() {
auto flagValue = traceTurboModulePromiseRejectionsOnAndroid_.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(32, "traceTurboModulePromiseRejectionsOnAndroid");

flagValue = currentProvider_->traceTurboModulePromiseRejectionsOnAndroid();
traceTurboModulePromiseRejectionsOnAndroid_ = flagValue;
}

return flagValue.value();
}

bool ReactNativeFeatureFlagsAccessor::unstable_enableTurboModuleSyncVoidMethods() {
auto flagValue = unstable_enableTurboModuleSyncVoidMethods_.load();

Expand All @@ -614,7 +632,7 @@ bool ReactNativeFeatureFlagsAccessor::unstable_enableTurboModuleSyncVoidMethods(
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.

markFlagAsAccessed(32, "unstable_enableTurboModuleSyncVoidMethods");
markFlagAsAccessed(33, "unstable_enableTurboModuleSyncVoidMethods");

flagValue = currentProvider_->unstable_enableTurboModuleSyncVoidMethods();
unstable_enableTurboModuleSyncVoidMethods_ = flagValue;
Expand All @@ -632,7 +650,7 @@ bool ReactNativeFeatureFlagsAccessor::useImmediateExecutorInAndroidBridgeless()
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.

markFlagAsAccessed(33, "useImmediateExecutorInAndroidBridgeless");
markFlagAsAccessed(34, "useImmediateExecutorInAndroidBridgeless");

flagValue = currentProvider_->useImmediateExecutorInAndroidBridgeless();
useImmediateExecutorInAndroidBridgeless_ = flagValue;
Expand All @@ -650,7 +668,7 @@ bool ReactNativeFeatureFlagsAccessor::useModernRuntimeScheduler() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.

markFlagAsAccessed(34, "useModernRuntimeScheduler");
markFlagAsAccessed(35, "useModernRuntimeScheduler");

flagValue = currentProvider_->useModernRuntimeScheduler();
useModernRuntimeScheduler_ = flagValue;
Expand All @@ -668,7 +686,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(35, "useNativeViewConfigsInBridgelessMode");
markFlagAsAccessed(36, "useNativeViewConfigsInBridgelessMode");

flagValue = currentProvider_->useNativeViewConfigsInBridgelessMode();
useNativeViewConfigsInBridgelessMode_ = flagValue;
Expand All @@ -686,7 +704,7 @@ bool ReactNativeFeatureFlagsAccessor::useNewReactImageViewBackgroundDrawing() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.

markFlagAsAccessed(36, "useNewReactImageViewBackgroundDrawing");
markFlagAsAccessed(37, "useNewReactImageViewBackgroundDrawing");

flagValue = currentProvider_->useNewReactImageViewBackgroundDrawing();
useNewReactImageViewBackgroundDrawing_ = flagValue;
Expand All @@ -704,7 +722,7 @@ bool ReactNativeFeatureFlagsAccessor::useOptimisedViewPreallocationOnAndroid() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.

markFlagAsAccessed(37, "useOptimisedViewPreallocationOnAndroid");
markFlagAsAccessed(38, "useOptimisedViewPreallocationOnAndroid");

flagValue = currentProvider_->useOptimisedViewPreallocationOnAndroid();
useOptimisedViewPreallocationOnAndroid_ = flagValue;
Expand All @@ -722,7 +740,7 @@ bool ReactNativeFeatureFlagsAccessor::useRuntimeShadowNodeReferenceUpdate() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.

markFlagAsAccessed(38, "useRuntimeShadowNodeReferenceUpdate");
markFlagAsAccessed(39, "useRuntimeShadowNodeReferenceUpdate");

flagValue = currentProvider_->useRuntimeShadowNodeReferenceUpdate();
useRuntimeShadowNodeReferenceUpdate_ = flagValue;
Expand All @@ -740,7 +758,7 @@ bool ReactNativeFeatureFlagsAccessor::useRuntimeShadowNodeReferenceUpdateOnLayou
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.

markFlagAsAccessed(39, "useRuntimeShadowNodeReferenceUpdateOnLayout");
markFlagAsAccessed(40, "useRuntimeShadowNodeReferenceUpdateOnLayout");

flagValue = currentProvider_->useRuntimeShadowNodeReferenceUpdateOnLayout();
useRuntimeShadowNodeReferenceUpdateOnLayout_ = flagValue;
Expand All @@ -758,7 +776,7 @@ bool ReactNativeFeatureFlagsAccessor::useStateAlignmentMechanism() {
// be accessing the provider multiple times but the end state of this
// instance and the returned flag value would be the same.

markFlagAsAccessed(40, "useStateAlignmentMechanism");
markFlagAsAccessed(41, "useStateAlignmentMechanism");

flagValue = currentProvider_->useStateAlignmentMechanism();
useStateAlignmentMechanism_ = flagValue;
Expand Down
Loading

0 comments on commit 992e4a1

Please sign in to comment.