Display JS component stack in native view exceptions

Reviewed By: mdvacca

Differential Revision: D7578033

fbshipit-source-id: 4dc393cddf8487db58cc3a9fefbff220983ba9da
This commit is contained in:
Andrew Chen (Eng)
2018-04-17 17:17:12 -07:00
committed by Facebook Github Bot
parent c4ab03a18e
commit ff9b3c6517
7 changed files with 102 additions and 115 deletions

View File

@@ -9,16 +9,25 @@
*/
'use strict';
var JSDevSupportModule = {
getJSHierarchy: function (tag: string) {
const hook = window.__REACT_DEVTOOLS_GLOBAL_HOOK__;
const renderers = hook._renderers;
const keys = Object.keys(renderers);
const renderer = renderers[keys[0]];
const JSDevSupport = require('NativeModules').JSDevSupport;
const ReactNative = require('ReactNative');
var result = renderer.getInspectorDataForViewTag(tag);
var path = result.hierarchy.map( (item) => item.name).join(' -> ');
require('NativeModules').JSDevSupport.setResult(path, null);
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);
}
},
};