Delete deprecated JSIModule methods (#42115)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/42115

React Native Android had a concept called JSIModules, which iOS doesn't have. The JSIModule concept was introduced in the early stages of the Fabric project to represent modules that interact with JS through JSI and they are not NativeModules.

In the new architecture this concept is not really necessary and these interfaces were only used to initialize and destroy the Fabric renderer and TurboModule Manager in react native core. Bridgeless mode doesn’t use JSIModule anymore. Also, it has an explicit list of supported JSI module types, so is not open for extension.
In order to simplify RN concepts and reduce confusion with TurboModules, which also "use JSI", deleting everything related to JSIModule. This was already deprecated in 0.74.0.

Please use ReactInstanceEventListener to subscribe for react instance events instead of getJSIModule() and we recommend using TurboModules instead of JSIModules.

Changelog:
[General][Breaking] Delete JSIModule

Reviewed By: javache, cortinico

Differential Revision: D49597702

fbshipit-source-id: bc2bc190aafaf559336b341b50ffabf413474105
This commit is contained in:
Arushi Kesarwani
2024-04-19 11:54:36 -07:00
committed by Facebook GitHub Bot
parent ac3261ff60
commit 73b4d67a78
12 changed files with 1 additions and 270 deletions
@@ -561,13 +561,11 @@ public final class com/facebook/react/bridge/CallbackImpl : com/facebook/react/b
public abstract interface class com/facebook/react/bridge/CatalystInstance : com/facebook/react/bridge/JSBundleLoaderDelegate, com/facebook/react/bridge/JSInstance, com/facebook/react/bridge/MemoryPressureListener {
public abstract fun addBridgeIdleDebugListener (Lcom/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener;)V
public abstract fun addJSIModules (Ljava/util/List;)V
public abstract fun callFunction (Ljava/lang/String;Ljava/lang/String;Lcom/facebook/react/bridge/NativeArray;)V
public abstract fun destroy ()V
public abstract fun extendNativeModules (Lcom/facebook/react/bridge/NativeModuleRegistry;)V
public abstract fun getFabricUIManager ()Lcom/facebook/react/bridge/UIManager;
public abstract fun getJSCallInvokerHolder ()Lcom/facebook/react/turbomodule/core/interfaces/CallInvokerHolder;
public abstract fun getJSIModule (Lcom/facebook/react/bridge/JSIModuleType;)Lcom/facebook/react/bridge/JSIModule;
public abstract fun getJSModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/JavaScriptModule;
public abstract fun getJavaScriptContextHolder ()Lcom/facebook/react/bridge/JavaScriptContextHolder;
public abstract fun getNativeMethodCallInvokerHolder ()Lcom/facebook/react/turbomodule/core/interfaces/NativeMethodCallInvokerHolder;
@@ -586,13 +584,11 @@ public abstract interface class com/facebook/react/bridge/CatalystInstance : com
public abstract fun removeBridgeIdleDebugListener (Lcom/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener;)V
public abstract fun runJSBundle ()V
public abstract fun setFabricUIManager (Lcom/facebook/react/bridge/UIManager;)V
public abstract fun setTurboModuleManager (Lcom/facebook/react/bridge/JSIModule;)V
public abstract fun setTurboModuleRegistry (Lcom/facebook/react/internal/turbomodule/core/interfaces/TurboModuleRegistry;)V
}
public class com/facebook/react/bridge/CatalystInstanceImpl : com/facebook/react/bridge/CatalystInstance {
public fun addBridgeIdleDebugListener (Lcom/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener;)V
public fun addJSIModules (Ljava/util/List;)V
public fun callFunction (Lcom/facebook/react/bridge/CatalystInstanceImpl$PendingJSCall;)V
public fun callFunction (Ljava/lang/String;Ljava/lang/String;Lcom/facebook/react/bridge/NativeArray;)V
public fun destroy ()V
@@ -600,7 +596,6 @@ public class com/facebook/react/bridge/CatalystInstanceImpl : com/facebook/react
public fun getFabricUIManager ()Lcom/facebook/react/bridge/UIManager;
public fun getJSCallInvokerHolder ()Lcom/facebook/react/turbomodule/core/CallInvokerHolderImpl;
public synthetic fun getJSCallInvokerHolder ()Lcom/facebook/react/turbomodule/core/interfaces/CallInvokerHolder;
public fun getJSIModule (Lcom/facebook/react/bridge/JSIModuleType;)Lcom/facebook/react/bridge/JSIModule;
public fun getJSModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/JavaScriptModule;
public fun getJavaScriptContextHolder ()Lcom/facebook/react/bridge/JavaScriptContextHolder;
public fun getNativeMethodCallInvokerHolder ()Lcom/facebook/react/turbomodule/core/NativeMethodCallInvokerHolderImpl;
@@ -626,7 +621,6 @@ public class com/facebook/react/bridge/CatalystInstanceImpl : com/facebook/react
public fun setFabricUIManager (Lcom/facebook/react/bridge/UIManager;)V
public fun setGlobalVariable (Ljava/lang/String;Ljava/lang/String;)V
public fun setSourceURLs (Ljava/lang/String;Ljava/lang/String;)V
public fun setTurboModuleManager (Lcom/facebook/react/bridge/JSIModule;)V
public fun setTurboModuleRegistry (Lcom/facebook/react/internal/turbomodule/core/interfaces/TurboModuleRegistry;)V
}
@@ -796,31 +790,6 @@ public abstract interface class com/facebook/react/bridge/JSExceptionHandler {
public abstract fun handleException (Ljava/lang/Exception;)V
}
public abstract interface class com/facebook/react/bridge/JSIModule {
public abstract fun initialize ()V
public abstract fun invalidate ()V
}
public abstract interface class com/facebook/react/bridge/JSIModulePackage {
public abstract fun getJSIModules (Lcom/facebook/react/bridge/ReactApplicationContext;Lcom/facebook/react/bridge/JavaScriptContextHolder;)Ljava/util/List;
}
public abstract interface class com/facebook/react/bridge/JSIModuleProvider {
public abstract fun get ()Lcom/facebook/react/bridge/JSIModule;
}
public abstract interface class com/facebook/react/bridge/JSIModuleSpec {
public abstract fun getJSIModuleProvider ()Lcom/facebook/react/bridge/JSIModuleProvider;
public abstract fun getJSIModuleType ()Lcom/facebook/react/bridge/JSIModuleType;
}
public final class com/facebook/react/bridge/JSIModuleType : java/lang/Enum {
public static final field TurboModuleManager Lcom/facebook/react/bridge/JSIModuleType;
public static final field UIManager Lcom/facebook/react/bridge/JSIModuleType;
public static fun valueOf (Ljava/lang/String;)Lcom/facebook/react/bridge/JSIModuleType;
public static fun values ()[Lcom/facebook/react/bridge/JSIModuleType;
}
public class com/facebook/react/bridge/JSONArguments {
public fun <init> ()V
public static fun fromJSONArray (Lorg/json/JSONArray;)Lcom/facebook/react/bridge/ReadableArray;
@@ -3706,13 +3675,11 @@ public abstract class com/facebook/react/runtime/BindingsInstaller {
public final class com/facebook/react/runtime/BridgelessCatalystInstance : com/facebook/react/bridge/CatalystInstance {
public fun <init> (Lcom/facebook/react/runtime/ReactHostImpl;)V
public fun addBridgeIdleDebugListener (Lcom/facebook/react/bridge/NotThreadSafeBridgeIdleDebugListener;)V
public fun addJSIModules (Ljava/util/List;)V
public fun callFunction (Ljava/lang/String;Ljava/lang/String;Lcom/facebook/react/bridge/NativeArray;)V
public fun destroy ()V
public fun extendNativeModules (Lcom/facebook/react/bridge/NativeModuleRegistry;)V
public fun getFabricUIManager ()Lcom/facebook/react/bridge/UIManager;
public fun getJSCallInvokerHolder ()Lcom/facebook/react/turbomodule/core/interfaces/CallInvokerHolder;
public fun getJSIModule (Lcom/facebook/react/bridge/JSIModuleType;)Lcom/facebook/react/bridge/JSIModule;
public fun getJSModule (Ljava/lang/Class;)Lcom/facebook/react/bridge/JavaScriptModule;
public fun getJavaScriptContextHolder ()Lcom/facebook/react/bridge/JavaScriptContextHolder;
public fun getNativeMethodCallInvokerHolder ()Lcom/facebook/react/turbomodule/core/interfaces/NativeMethodCallInvokerHolder;
@@ -3736,7 +3703,6 @@ public final class com/facebook/react/runtime/BridgelessCatalystInstance : com/f
public fun runJSBundle ()V
public fun setFabricUIManager (Lcom/facebook/react/bridge/UIManager;)V
public fun setSourceURLs (Ljava/lang/String;Ljava/lang/String;)V
public fun setTurboModuleManager (Lcom/facebook/react/bridge/JSIModule;)V
public fun setTurboModuleRegistry (Lcom/facebook/react/internal/turbomodule/core/interfaces/TurboModuleRegistry;)V
}
@@ -16,7 +16,6 @@ import com.facebook.react.internal.turbomodule.core.interfaces.TurboModuleRegist
import com.facebook.react.turbomodule.core.interfaces.CallInvokerHolder;
import com.facebook.react.turbomodule.core.interfaces.NativeMethodCallInvokerHolder;
import java.util.Collection;
import java.util.List;
/**
* A higher level API on top of the asynchronous JSC bridge. This provides an environment allowing
@@ -72,13 +71,6 @@ public interface CatalystInstance
@Nullable
NativeModule getNativeModule(String moduleName);
@Deprecated(
since =
"getJSIModule(JSIModuleType moduleType) is deprecated and will be deleted in the future."
+ " Please use ReactInstanceEventListener to subscribe for react instance events"
+ " instead.")
JSIModule getJSIModule(JSIModuleType moduleType);
Collection<NativeModule> getNativeModules();
/**
@@ -122,9 +114,6 @@ public interface CatalystInstance
RuntimeScheduler getRuntimeScheduler();
@Deprecated
<T extends JSIModule> void addJSIModules(List<JSIModuleSpec<T>> jsiModules);
/**
* Returns a hybrid object that contains a pointer to a JS CallInvoker, which is used to schedule
* work on the JS Thread. Required for TurboModuleManager initialization.
@@ -137,13 +126,6 @@ public interface CatalystInstance
*/
NativeMethodCallInvokerHolder getNativeMethodCallInvokerHolder();
@Deprecated(
since =
"setTurboModuleManager(JSIModule getter) is deprecated and will be deleted in the future."
+ " Please use setTurboModuleRegistry(TurboModuleRegistry"
+ " turboModuleRegistry)instead.")
void setTurboModuleManager(JSIModule getter);
@DeprecatedInNewArchitecture(
message =
"This method will be deprecated later as part of Stable APIs with bridge removal and not"
@@ -35,7 +35,6 @@ import com.facebook.systrace.TraceListener;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.atomic.AtomicInteger;
@@ -92,7 +91,6 @@ public class CatalystInstanceImpl implements CatalystInstance {
private final Object mJSCallsPendingInitLock = new Object();
private final NativeModuleRegistry mNativeModuleRegistry;
private final JSIModuleRegistry mJSIModuleRegistry = new JSIModuleRegistry();
private final JSExceptionHandler mJSExceptionHandler;
private final MessageQueueThread mNativeModulesQueueThread;
private boolean mInitialized = false;
@@ -357,7 +355,6 @@ public class CatalystInstanceImpl implements CatalystInstance {
mNativeModulesQueueThread.runOnQueue(
() -> {
mNativeModuleRegistry.notifyJSInstanceDestroy();
mJSIModuleRegistry.notifyJSInstanceDestroy();
if (mFabricUIManager != null) {
mFabricUIManager.invalidate();
}
@@ -543,17 +540,6 @@ public class CatalystInstanceImpl implements CatalystInstance {
public native RuntimeScheduler getRuntimeScheduler();
@Override
@Deprecated
public <T extends JSIModule> void addJSIModules(List<JSIModuleSpec<T>> jsiModules) {
mJSIModuleRegistry.registerModules(jsiModules);
}
@Override
public JSIModule getJSIModule(JSIModuleType moduleType) {
return mJSIModuleRegistry.getModule(moduleType);
}
private native long getJavaScriptContext();
private void incrementPendingJSCalls() {
@@ -571,10 +557,6 @@ public class CatalystInstanceImpl implements CatalystInstance {
}
}
public void setTurboModuleManager(JSIModule module) {
mTurboModuleRegistry = (TurboModuleRegistry) module;
}
@Override
public void setTurboModuleRegistry(TurboModuleRegistry turboModuleRegistry) {
mTurboModuleRegistry = turboModuleRegistry;
@@ -1,22 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.bridge;
/** Marker interface used to represent a JSI Module. */
public interface JSIModule {
/**
* This is called at the end of {@link CatalystApplicationFragment#createCatalystInstance()} after
* the CatalystInstance has been created, in order to initialize NativeModules that require the
* CatalystInstance or JS modules.
*/
void initialize();
/** Called before {CatalystInstance#onHostDestroy} */
void invalidate();
}
@@ -1,37 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.bridge;
class JSIModuleHolder {
private JSIModule mModule;
private final JSIModuleSpec mSpec;
public JSIModuleHolder(JSIModuleSpec spec) {
mSpec = spec;
}
public JSIModule getJSIModule() {
if (mModule == null) {
synchronized (this) {
if (mModule != null) {
return mModule;
}
mModule = mSpec.getJSIModuleProvider().get();
mModule.initialize();
}
}
return mModule;
}
public void notifyJSInstanceDestroy() {
if (mModule != null) {
mModule.invalidate();
}
}
}
@@ -1,20 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.bridge;
import java.util.List;
/** Interface used to initialize JSI Modules into the JSI Bridge. */
public interface JSIModulePackage {
/**
* @return a {@link List< JSIModuleSpec >} that contain the list of JSI Modules.
*/
List<JSIModuleSpec> getJSIModules(
ReactApplicationContext reactApplicationContext, JavaScriptContextHolder jsContext);
}
@@ -1,13 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.bridge;
public interface JSIModuleProvider<T extends JSIModule> {
T get();
}
@@ -1,48 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.bridge;
import com.facebook.infer.annotation.Assertions;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
class JSIModuleRegistry {
private final Map<JSIModuleType, JSIModuleHolder> mModules = new HashMap<>();
public JSIModuleRegistry() {}
public JSIModule getModule(JSIModuleType moduleType) {
JSIModuleHolder jsiModuleHolder = mModules.get(moduleType);
if (jsiModuleHolder == null) {
throw new IllegalArgumentException("Unable to find JSIModule for class " + moduleType);
}
return Assertions.assertNotNull(jsiModuleHolder.getJSIModule());
}
public <T extends JSIModule> void registerModules(List<JSIModuleSpec<T>> jsiModules) {
for (JSIModuleSpec<T> spec : jsiModules) {
mModules.put(spec.getJSIModuleType(), new JSIModuleHolder(spec));
}
}
public void notifyJSInstanceDestroy() {
for (Map.Entry<JSIModuleType, JSIModuleHolder> entry : mModules.entrySet()) {
JSIModuleType moduleType = entry.getKey();
// Don't call TurboModuleManager.onCatalystInstanceDestroy
if (moduleType == JSIModuleType.TurboModuleManager) {
continue;
}
JSIModuleHolder moduleHolder = entry.getValue();
moduleHolder.notifyJSInstanceDestroy();
}
}
}
@@ -1,16 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.bridge;
/** Holder class used to register {@link JSIModule} into JSI Bridge. */
public interface JSIModuleSpec<T extends JSIModule> {
JSIModuleType getJSIModuleType();
JSIModuleProvider<T> getJSIModuleProvider();
}
@@ -1,17 +0,0 @@
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
package com.facebook.react.bridge;
/**
* A list of support JSIModules. These are usually core infra pieces, so there should be an explicit
* list.
*/
public enum JSIModuleType {
TurboModuleManager,
UIManager,
}
@@ -591,10 +591,7 @@ public abstract class ReactContext extends ContextWrapper {
* @return The UIManager when CatalystInstance is active.
*/
public @Nullable UIManager getFabricUIManager() {
UIManager uiManager = mCatalystInstance.getFabricUIManager();
return uiManager != null
? uiManager
: (UIManager) mCatalystInstance.getJSIModule(JSIModuleType.UIManager);
return mCatalystInstance.getFabricUIManager();
}
/**
@@ -10,9 +10,6 @@ package com.facebook.react.runtime
import android.content.res.AssetManager
import com.facebook.proguard.annotations.DoNotStrip
import com.facebook.react.bridge.CatalystInstance
import com.facebook.react.bridge.JSIModule
import com.facebook.react.bridge.JSIModuleSpec
import com.facebook.react.bridge.JSIModuleType
import com.facebook.react.bridge.JavaScriptContextHolder
import com.facebook.react.bridge.JavaScriptModule
import com.facebook.react.bridge.NativeArray
@@ -107,13 +104,6 @@ public class BridgelessCatalystInstance(private val reactHost: ReactHostImpl) :
override fun getNativeModule(moduleName: String): NativeModule? =
reactHost.getNativeModule(moduleName)
@Deprecated(
message =
"getJSIModule(JSIModuleType moduleType) is deprecated and will be deleted in the future. Please use ReactInstanceEventListener to subscribe for react instance events instead.")
override fun getJSIModule(moduleType: JSIModuleType): JSIModule {
throw UnsupportedOperationException("Unimplemented method 'getJSIModule'")
}
override fun getNativeModules(): Collection<NativeModule> = reactHost.getNativeModules()
override fun extendNativeModules(modules: NativeModuleRegistry) {
@@ -150,11 +140,6 @@ public class BridgelessCatalystInstance(private val reactHost: ReactHostImpl) :
throw UnsupportedOperationException("Unimplemented method 'getRuntimeScheduler'")
}
@Deprecated(message = "This API is unsupported in the New Architecture.")
override fun <T : JSIModule> addJSIModules(jsiModules: List<JSIModuleSpec<T>>) {
throw UnsupportedOperationException("Unimplemented method 'addJSIModules'")
}
override fun getJSCallInvokerHolder(): CallInvokerHolder? {
return reactHost.getJSCallInvokerHolder()
}
@@ -163,14 +148,6 @@ public class BridgelessCatalystInstance(private val reactHost: ReactHostImpl) :
throw UnsupportedOperationException("Unimplemented method 'getNativeMethodCallInvokerHolder'")
}
@Deprecated(
message =
"setTurboModuleManager(JSIModule getter) is deprecated and will be deleted in the future. Please use setTurboModuleRegistry(TurboModuleRegistry turboModuleRegistry) instead.",
replaceWith = ReplaceWith("setTurboModuleRegistry(turboModuleRegistry)"))
override fun setTurboModuleManager(getter: JSIModule) {
throw UnsupportedOperationException("Unimplemented method 'setTurboModuleManager'")
}
@DeprecatedInNewArchitecture(
message =
"This method will be deprecated later as part of Stable APIs with bridge removal and not encouraged usage.")