From b42371da5a41916522b569a66c0a126333cf9cac Mon Sep 17 00:00:00 2001 From: Ramanpreet Nara Date: Tue, 10 Dec 2019 12:32:28 -0800 Subject: [PATCH] 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 --- .../FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h | 2 +- Libraries/Utilities/NativeJSDevSupport.js | 2 +- .../com/facebook/fbreact/specs/NativeJSDevSupportSpec.java | 3 +-- 3 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h index bb1c8d2d99a..4e361e2bef4 100644 --- a/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h +++ b/Libraries/FBReactNativeSpec/FBReactNativeSpec/FBReactNativeSpec.h @@ -1682,7 +1682,7 @@ namespace JS { } @protocol NativeJSDevSupportSpec -- (void)onSuccess:(NSDictionary *)data; +- (void)onSuccess:(NSString *)data; - (void)onFailure:(double)errorCode error:(NSString *)error; - (facebook::react::ModuleConstants)constantsToExport; diff --git a/Libraries/Utilities/NativeJSDevSupport.js b/Libraries/Utilities/NativeJSDevSupport.js index 3128d3d83bd..0c140f0f962 100644 --- a/Libraries/Utilities/NativeJSDevSupport.js +++ b/Libraries/Utilities/NativeJSDevSupport.js @@ -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; } diff --git a/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeJSDevSupportSpec.java b/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeJSDevSupportSpec.java index 4663777a6c2..4e76f968ae6 100644 --- a/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeJSDevSupportSpec.java +++ b/ReactAndroid/src/main/java/com/facebook/fbreact/specs/NativeJSDevSupportSpec.java @@ -16,7 +16,6 @@ import com.facebook.react.bridge.ReactApplicationContext; 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 abstract class NativeJSDevSupportSpec extends ReactContextBaseJavaModule public abstract void onFailure(double errorCode, String error); @ReactMethod - public abstract void onSuccess(ReadableMap data); + public abstract void onSuccess(String data); protected abstract Map getTypedExportedConstants();