Skip to content
Permalink
Browse files
Fix NativeJSDevSupport.onSuccess
Summary:
`JSDevSupport.onSuccess` is called in `JSDevSupportModule.getJSHierarchy`:

```
const JSDevSupportModule = {
  getJSHierarchy: function(tag: number) {
    try {
      const {
        computeComponentStackForErrorReporting,
      } = ReactNative.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED;
      const componentStack = computeComponentStackForErrorReporting(tag);
      if (!componentStack) {
        JSDevSupport.onFailure(
          JSDevSupport.ERROR_CODE_VIEW_NOT_FOUND,
          "Component stack doesn't exist for tag " + tag,
        );
      } else {
        JSDevSupport.onSuccess(componentStack);
      }
    } catch (e) {
      JSDevSupport.onFailure(JSDevSupport.ERROR_CODE_EXCEPTION, e.message);
    }
  },
};
```

If you look at the implementation of `computeComponentStackForErrorReporting`, it returns a `string`. The Java NativeModule also accepts a `String` for the argument to `JSDevSupport.onSuccess`. So, I've changed the `NativeJSDevSupport.onSuccess` method signature to match the native implementation (i.e: accept a string).

Changelog:
[General] [Fixed] - Correct argument types of NativeJSDevSupport.onSuccess

Reviewed By: fkgozali

Differential Revision: D18908306

fbshipit-source-id: 1c9a5c6fe5b3a81b25baed520e586ebf7e2514f8
  • Loading branch information
RSNara authored and facebook-github-bot committed Dec 10, 2019
1 parent 3714bfe commit b42371da5a41916522b569a66c0a126333cf9cac
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 4 deletions.
@@ -1682,7 +1682,7 @@ namespace JS {
}
@protocol NativeJSDevSupportSpec <RCTBridgeModule, RCTTurboModule>

- (void)onSuccess:(NSDictionary *)data;
- (void)onSuccess:(NSString *)data;
- (void)onFailure:(double)errorCode
error:(NSString *)error;
- (facebook::react::ModuleConstants<JS::NativeJSDevSupport::Constants::Builder>)constantsToExport;
@@ -18,7 +18,7 @@ export interface Spec extends TurboModule {
ERROR_CODE_EXCEPTION: number,
ERROR_CODE_VIEW_NOT_FOUND: number,
|};
+onSuccess: (data: Object) => void;
+onSuccess: (data: string) => void;
+onFailure: (errorCode: number, error: string) => void;
}

@@ -16,7 +16,6 @@
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.ReactModuleWithSpec;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.build.ReactBuildConfig;
import com.facebook.react.turbomodule.core.interfaces.TurboModule;
import java.util.Arrays;
@@ -34,7 +33,7 @@ public NativeJSDevSupportSpec(ReactApplicationContext reactContext) {
public abstract void onFailure(double errorCode, String error);

@ReactMethod
public abstract void onSuccess(ReadableMap data);
public abstract void onSuccess(String data);

protected abstract Map<String, Object> getTypedExportedConstants();

0 comments on commit b42371d

Please sign in to comment.