Skip to content

Commit 47b45df

Browse files
cortinicokelset
authored andcommitted
Make sure the Native RuntimeScheduler is initialized on Old Arch (#37517)
Summary: Pull Request resolved: #37517 Fixes #35778 We got reports of regressions on `useEffect` starting from 0.69+ when on Hermes. The issue seems to be caused by a bump of the `scheduler` package from 0.20 to 0.21. In [email protected], the method `setImmediate` gets called if available (see facebook/react#20834). This causes React Native to use Microtasks which ends up in changing the semantic of useEffect. The solution is to use the Native RuntimeScheduler properly. On Paper specifically, we never initialized it as it's effectively initialized by the TurboModuleManagerDelegate. Here I trigger the initialization of it on Paper as well. Changelog: [Android] [Fixed] - Make sure the Native RuntimeScheduler is initialized on Old Arch Reviewed By: sammy-SC Differential Revision: D46024807 fbshipit-source-id: d72cd774df58410467644cddeaaf37e3c227b505
1 parent cddcf09 commit 47b45df

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/ReactInstanceManager.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1360,6 +1360,15 @@ private ReactApplicationContext createReactContext(
13601360

13611361
reactContext.initializeWithInstance(catalystInstance);
13621362

1363+
if (ReactFeatureFlags.unstable_useRuntimeSchedulerAlways) {
1364+
// On Old Architecture, we need to initialize the Native Runtime Scheduler so that
1365+
// the `nativeRuntimeScheduler` object is registered on JS.
1366+
// On New Architecture, this is normally triggered by instantiate a TurboModuleManager.
1367+
// Here we invoke getRuntimeScheduler() to trigger the creation of it regardless of the
1368+
// architecture so it will always be there.
1369+
catalystInstance.getRuntimeScheduler();
1370+
}
1371+
13631372
if (ReactFeatureFlags.useTurboModules && mTMMDelegateBuilder != null) {
13641373
TurboModuleManagerDelegate tmmDelegate =
13651374
mTMMDelegateBuilder

packages/react-native/ReactAndroid/src/main/java/com/facebook/react/config/ReactFeatureFlags.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ public class ReactFeatureFlags {
4242
*/
4343
public static volatile boolean unstable_useFabricInterop = false;
4444

45+
/**
46+
* Should this application always use the Native RuntimeScheduler? If yes, we'll be instantiating
47+
* it over all the architectures (both Old and New). This is intentionally set to true as we want
48+
* to use it more as a kill-switch to turn off this feature to potentially debug issues.
49+
*/
50+
public static volatile boolean unstable_useRuntimeSchedulerAlways = true;
51+
4552
/**
4653
* Feature flag to enable the new bridgeless architecture. Note: Enabling this will force enable
4754
* the following flags: `useTurboModules` & `enableFabricRenderer`.

0 commit comments

Comments
 (0)