@samitouri / QOS-React / commits / 4aea7c3fad

RN Inspector guard against clicks outside of RN (#9911)

Brian Vaughn committed Jun 9, 2017 at 16:10 UTC 4aea7c3fade5f5dfc64f74efdd1e5888670d92f6
2 files changed +24 -3
src/renderers/native/ReactNativeFiberInspector.js
+13 -3
@@ -89,9 +89,19 @@ if (__DEV__) {
89 };
90
91 getInspectorDataForViewTag = function(viewTag: number): Object {
92 - const fiber = findCurrentFiberUsingSlowPath(
93 - getClosestInstanceFromNode(viewTag),
94 - );
92 + const closestInstance = getClosestInstanceFromNode(viewTag);
93 +
94 + // Handle case where user clicks outside of ReactNative
95 + if (!closestInstance) {
96 + return {
97 + hierarchy: [],
98 + props: emptyObject,
99 + selection: null,
100 + source: null,
101 + };
102 + }
103 +
104 + const fiber = findCurrentFiberUsingSlowPath(closestInstance);
105 const fiberHierarchy = getOwnerHierarchy(fiber);
106 const instance = lastNonHostInstance(fiberHierarchy);
107 const hierarchy = createHierarchy(fiberHierarchy);
src/renderers/native/ReactNativeStackInspector.js
+11
@@ -67,6 +67,17 @@ if (__DEV__) {
67 const component = ReactNativeComponentTree.getClosestInstanceFromNode(
68 viewTag,
69 );
70 +
71 + // Handle case where user clicks outside of ReactNative
72 + if (!component) {
73 + return {
74 + hierarchy: [],
75 + props: emptyObject,
76 + selection: null,
77 + source: null,
78 + };
79 + }
80 +
81 const componentHierarchy = getOwnerHierarchy(component);
82 const instance = lastNotNativeInstance(componentHierarchy);
83 const hierarchy = createHierarchy(componentHierarchy);