Skip to content

Commit

Permalink
Allow native module loads during react instance init
Browse files Browse the repository at this point in the history
Summary:
## Context
Right now, the ReactInstance construtor eagerly initializes native modules.

## Problem
When these modules initialize, they may load other modules. But, all those loads will fail, because the react instance is in the process of being constructed.

## Changes
Eagerly initialize modules after the react instance is created. That way, these native module requires work.

Changelog: [Internal]

Reviewed By: javache

Differential Revision: D58537536

fbshipit-source-id: d0e424df708ec35b014f5cecda11e8756e8f4346
  • Loading branch information
RSNara authored and facebook-github-bot committed Jun 14, 2024
1 parent 74d030d commit e78742a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,9 @@ private Task<ReactInstance> getOrCreateReactInstanceTask() {
getOrCreateReactHostInspectorTarget());
mReactInstance = instance;

// eagerly initailize turbo modules
instance.initializeEagerTurboModules();

MemoryPressureListener memoryPressureListener =
createMemoryPressureListener(instance);
mMemoryPressureListener = memoryPressureListener;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,11 +198,6 @@ final class ReactInstance {
getJSCallInvokerHolder(),
getNativeMethodCallInvokerHolder());

// Eagerly initialize TurboModules
for (String moduleName : mTurboModuleManager.getEagerInitModuleNames()) {
mTurboModuleManager.getModule(moduleName);
}

Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);

// Set up Fabric
Expand Down Expand Up @@ -300,6 +295,13 @@ final class ReactInstance {
Systrace.endSection(Systrace.TRACE_TAG_REACT_JAVA_BRIDGE);
}

void initializeEagerTurboModules() {
// Eagerly initialize TurboModules
for (String moduleName : mTurboModuleManager.getEagerInitModuleNames()) {
mTurboModuleManager.getModule(moduleName);
}
}

private static synchronized void loadLibraryIfNeeded() {
if (!sIsLibraryLoaded) {
SoLoader.loadLibrary("rninstance");
Expand Down

0 comments on commit e78742a

Please sign in to comment.