Skip to content

Commit

Permalink
Unregister JSDevSupport from DebugCorePackage
Browse files Browse the repository at this point in the history
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
  • Loading branch information
RSNara authored and facebook-github-bot committed Dec 20, 2019
1 parent 5e9f4e6 commit c20963e
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
@ReactModuleList(
nativeModules = {
JSCHeapCapture.class,
JSDevSupport.class,
})
public class DebugCorePackage extends TurboReactPackage {
public DebugCorePackage() {}
Expand All @@ -37,8 +36,6 @@ public NativeModule getModule(String name, ReactApplicationContext reactContext)
switch (name) {
case JSCHeapCapture.TAG:
return new JSCHeapCapture(reactContext);
case JSDevSupport.MODULE_NAME:
return new JSDevSupport(reactContext);
default:
throw new IllegalArgumentException(
"In CoreModulesPackage, could not find Native module for " + name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import java.util.HashMap;
import java.util.Map;

@ReactModule(name = JSDevSupport.MODULE_NAME, canOverrideExistingModule = true)
@ReactModule(name = JSDevSupport.MODULE_NAME)
public class JSDevSupport extends NativeJSDevSupportSpec {
public static final String MODULE_NAME = "JSDevSupport";

Expand Down

0 comments on commit c20963e

Please sign in to comment.