Unregister JSDevSupport from DebugCorePackage

Summary:
## Problem
`DebugCorePackage` is a `TurboReactPackage`. To register a `TurboReactPackage`s NativeModules, the `NativeModuleRegistryBuilder` loops over all `ReactModuleInfo`s in the package's auto-generated `ReactModuleInfo` list. This list is generated from the `ReactModuleList` annotation of the package using our annotation processors. Because `JSDevSupport` was in its package's `ReactModuleList` annotation, we generated a `ReactModuleInfo` object for it. Therefore, `NativeModuleRegistryBuilder` registered `JSDevSupport` twice (once in `DebugCorePackage` and twice in `Fb4aReactPackage`).

## How did this work before?
`JSDevSupport` was always a part of the `ReactModuleList` annotation of `DebugCorePackage`. However, before D18974084 landed, there were two key things that made this work:
1. `DebugCorePackage` was a `LazyReactPackage`,
2. The `DebugCorePackage.getNativeModules()` did not return a `ModuleHolder` for `JSDevSupport`.

For `LazyReactPackage`s, `NativeModuleRegistryBuilder` calls `LazyReactPackage.getNativeModuleIterator()` to register NativeModules. The iterator returned from `LazyReactPackage.getNativeModuleIterator()`, in this case, loops over the NativeModules returned from `DebugCorePackage.getNativeModules()`. Therefore, we don't register any NativeModules that aren't in `DebugCorePackage.getNativeModules()`. Since `DebugCorePackage.getNativeModules()` didn't contain `JSDevSupport`, it wasn't registered for the second time.

Changelog:
[Android][Fixed] - Unregister JSDevSupport from DebugCorePackage

Reviewed By: ejanzer

Differential Revision: D19187664

fbshipit-source-id: 34141c60542179567d75705937ba09ec8a3dfc2b
This commit is contained in:
Ramanpreet Nara 2019-12-20 08:24:01 -08:00 коммит произвёл Facebook Github Bot
Родитель 5e9f4e67d3
Коммит c20963e11c
2 изменённых файлов: 1 добавлений и 4 удалений

Просмотреть файл

@ -27,7 +27,6 @@ import java.util.Map;
@ReactModuleList( @ReactModuleList(
nativeModules = { nativeModules = {
JSCHeapCapture.class, JSCHeapCapture.class,
JSDevSupport.class,
}) })
public class DebugCorePackage extends TurboReactPackage { public class DebugCorePackage extends TurboReactPackage {
public DebugCorePackage() {} public DebugCorePackage() {}
@ -37,8 +36,6 @@ public class DebugCorePackage extends TurboReactPackage {
switch (name) { switch (name) {
case JSCHeapCapture.TAG: case JSCHeapCapture.TAG:
return new JSCHeapCapture(reactContext); return new JSCHeapCapture(reactContext);
case JSDevSupport.MODULE_NAME:
return new JSDevSupport(reactContext);
default: default:
throw new IllegalArgumentException( throw new IllegalArgumentException(
"In CoreModulesPackage, could not find Native module for " + name); "In CoreModulesPackage, could not find Native module for " + name);

Просмотреть файл

@ -17,7 +17,7 @@ import com.facebook.react.module.annotations.ReactModule;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ReactModule(name = JSDevSupport.MODULE_NAME, canOverrideExistingModule = true) @ReactModule(name = JSDevSupport.MODULE_NAME)
public class JSDevSupport extends NativeJSDevSupportSpec { public class JSDevSupport extends NativeJSDevSupportSpec {
public static final String MODULE_NAME = "JSDevSupport"; public static final String MODULE_NAME = "JSDevSupport";