Skip to content

Commit f54a048

Browse files
author
Brian Vaughn
committed
Remove feature flag guard around getInspectorDataForInstance export
1 parent 74eaf3e commit f54a048

10 files changed

+98
-112
lines changed

packages/react-native-renderer/src/ReactNativeFiberInspector.js

Lines changed: 90 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -19,128 +19,117 @@ import {HostComponent} from 'react-reconciler/src/ReactWorkTags';
1919
import invariant from 'shared/invariant';
2020
// Module provided by RN:
2121
import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
22-
import {enableGetInspectorDataForInstanceInProduction} from 'shared/ReactFeatureFlags';
2322
import {getClosestInstanceFromNode} from './ReactNativeComponentTree';
2423

2524
const emptyObject = {};
2625
if (__DEV__) {
2726
Object.freeze(emptyObject);
2827
}
2928

30-
let createHierarchy;
31-
let getHostNode;
32-
let getHostProps;
33-
let lastNonHostInstance;
34-
let getInspectorDataForInstance;
35-
let getOwnerHierarchy;
36-
let traverseOwnerTreeUp;
37-
38-
if (__DEV__ || enableGetInspectorDataForInstanceInProduction) {
39-
createHierarchy = function(fiberHierarchy) {
40-
return fiberHierarchy.map(fiber => ({
41-
name: getComponentNameFromType(fiber.type),
42-
getInspectorData: findNodeHandle => {
43-
return {
44-
props: getHostProps(fiber),
45-
source: fiber._debugSource,
46-
measure: callback => {
47-
// If this is Fabric, we'll find a ShadowNode and use that to measure.
48-
const hostFiber = findCurrentHostFiber(fiber);
49-
const shadowNode =
50-
hostFiber != null &&
51-
hostFiber.stateNode !== null &&
52-
hostFiber.stateNode.node;
53-
54-
if (shadowNode) {
55-
nativeFabricUIManager.measure(shadowNode, callback);
56-
} else {
57-
return UIManager.measure(
58-
getHostNode(fiber, findNodeHandle),
59-
callback,
60-
);
61-
}
62-
},
63-
};
64-
},
65-
}));
66-
};
29+
function createHierarchy(fiberHierarchy) {
30+
return fiberHierarchy.map(fiber => ({
31+
name: getComponentNameFromType(fiber.type),
32+
getInspectorData: findNodeHandle => {
33+
return {
34+
props: getHostProps(fiber),
35+
source: fiber._debugSource,
36+
measure: callback => {
37+
// If this is Fabric, we'll find a ShadowNode and use that to measure.
38+
const hostFiber = findCurrentHostFiber(fiber);
39+
const shadowNode =
40+
hostFiber != null &&
41+
hostFiber.stateNode !== null &&
42+
hostFiber.stateNode.node;
6743

68-
getHostNode = function(fiber: Fiber | null, findNodeHandle) {
69-
let hostNode;
70-
// look for children first for the hostNode
71-
// as composite fibers do not have a hostNode
72-
while (fiber) {
73-
if (fiber.stateNode !== null && fiber.tag === HostComponent) {
74-
hostNode = findNodeHandle(fiber.stateNode);
75-
}
76-
if (hostNode) {
77-
return hostNode;
78-
}
79-
fiber = fiber.child;
80-
}
81-
return null;
82-
};
44+
if (shadowNode) {
45+
nativeFabricUIManager.measure(shadowNode, callback);
46+
} else {
47+
return UIManager.measure(
48+
getHostNode(fiber, findNodeHandle),
49+
callback,
50+
);
51+
}
52+
},
53+
};
54+
},
55+
}));
56+
}
8357

84-
getHostProps = function(fiber) {
85-
const host = findCurrentHostFiber(fiber);
86-
if (host) {
87-
return host.memoizedProps || emptyObject;
58+
function getHostNode(fiber: Fiber | null, findNodeHandle) {
59+
let hostNode;
60+
// look for children first for the hostNode
61+
// as composite fibers do not have a hostNode
62+
while (fiber) {
63+
if (fiber.stateNode !== null && fiber.tag === HostComponent) {
64+
hostNode = findNodeHandle(fiber.stateNode);
8865
}
89-
return emptyObject;
90-
};
91-
92-
getInspectorDataForInstance = function(
93-
closestInstance: Fiber | null,
94-
): InspectorData {
95-
// Handle case where user clicks outside of ReactNative
96-
if (!closestInstance) {
97-
return {
98-
hierarchy: [],
99-
props: emptyObject,
100-
selectedIndex: null,
101-
source: null,
102-
};
66+
if (hostNode) {
67+
return hostNode;
10368
}
69+
fiber = fiber.child;
70+
}
71+
return null;
72+
}
10473

105-
const fiber = findCurrentFiberUsingSlowPath(closestInstance);
106-
const fiberHierarchy = getOwnerHierarchy(fiber);
107-
const instance = lastNonHostInstance(fiberHierarchy);
108-
const hierarchy = createHierarchy(fiberHierarchy);
109-
const props = getHostProps(instance);
110-
const source = instance._debugSource;
111-
const selectedIndex = fiberHierarchy.indexOf(instance);
74+
function getHostProps(fiber) {
75+
const host = findCurrentHostFiber(fiber);
76+
if (host) {
77+
return host.memoizedProps || emptyObject;
78+
}
79+
return emptyObject;
80+
}
11281

82+
function getInspectorDataForInstance(
83+
closestInstance: Fiber | null,
84+
): InspectorData {
85+
// Handle case where user clicks outside of ReactNative
86+
if (!closestInstance) {
11387
return {
114-
hierarchy,
115-
props,
116-
selectedIndex,
117-
source,
88+
hierarchy: [],
89+
props: emptyObject,
90+
selectedIndex: null,
91+
source: null,
11892
};
119-
};
93+
}
94+
95+
const fiber = findCurrentFiberUsingSlowPath(closestInstance);
96+
const fiberHierarchy = getOwnerHierarchy(fiber);
97+
const instance = lastNonHostInstance(fiberHierarchy);
98+
const hierarchy = createHierarchy(fiberHierarchy);
99+
const props = getHostProps(instance);
100+
const source = instance._debugSource;
101+
const selectedIndex = fiberHierarchy.indexOf(instance);
120102

121-
getOwnerHierarchy = function(instance: any) {
122-
const hierarchy = [];
123-
traverseOwnerTreeUp(hierarchy, instance);
124-
return hierarchy;
103+
return {
104+
hierarchy,
105+
props,
106+
selectedIndex,
107+
source,
125108
};
109+
}
110+
111+
function getOwnerHierarchy(instance: any) {
112+
const hierarchy = [];
113+
traverseOwnerTreeUp(hierarchy, instance);
114+
return hierarchy;
115+
}
126116

127-
lastNonHostInstance = function(hierarchy) {
128-
for (let i = hierarchy.length - 1; i > 1; i--) {
129-
const instance = hierarchy[i];
117+
function lastNonHostInstance(hierarchy) {
118+
for (let i = hierarchy.length - 1; i > 1; i--) {
119+
const instance = hierarchy[i];
130120

131-
if (instance.tag !== HostComponent) {
132-
return instance;
133-
}
121+
if (instance.tag !== HostComponent) {
122+
return instance;
134123
}
135-
return hierarchy[0];
136-
};
124+
}
125+
return hierarchy[0];
126+
}
137127

138-
traverseOwnerTreeUp = function(hierarchy, instance: any) {
139-
if (instance) {
140-
hierarchy.unshift(instance);
141-
traverseOwnerTreeUp(hierarchy, instance._debugOwner);
142-
}
143-
};
128+
function traverseOwnerTreeUp(hierarchy, instance: any) {
129+
if (instance) {
130+
hierarchy.unshift(instance);
131+
traverseOwnerTreeUp(hierarchy, instance._debugOwner);
132+
}
144133
}
145134

146135
let getInspectorDataForViewTag;

packages/shared/ReactFeatureFlags.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ export const enableNewReconciler = false;
106106

107107
export const disableNativeComponentFrames = false;
108108

109-
// Used by React Native in Facebook internal builds for UI review tools.
110-
export const enableGetInspectorDataForInstanceInProduction = false;
111-
112109
// Errors that are thrown while unmounting (or after in the case of passive effects)
113110
// should bypass any error boundaries that are also unmounting (or have unmounted)
114111
// and be handled by the nearest still-mounted boundary.

packages/shared/forks/ReactFeatureFlags.native-fb.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ export const disableNativeComponentFrames = false;
4848
export const skipUnmountedBoundaries = false;
4949
export const deletedTreeCleanUpLevel = 1;
5050
export const enableSuspenseLayoutEffectSemantics = false;
51-
export const enableGetInspectorDataForInstanceInProduction = true;
51+
5252
export const enableNewReconciler = false;
5353
export const deferRenderPhaseUpdateToNextBatch = true;
5454

packages/shared/forks/ReactFeatureFlags.native-oss.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = false;
4848
export const deletedTreeCleanUpLevel = 1;
4949
export const enableSuspenseLayoutEffectSemantics = false;
50-
export const enableGetInspectorDataForInstanceInProduction = false;
50+
5151
export const enableNewReconciler = false;
5252
export const deferRenderPhaseUpdateToNextBatch = true;
5353

packages/shared/forks/ReactFeatureFlags.test-renderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = false;
4848
export const deletedTreeCleanUpLevel = 1;
4949
export const enableSuspenseLayoutEffectSemantics = false;
50-
export const enableGetInspectorDataForInstanceInProduction = false;
50+
5151
export const enableNewReconciler = false;
5252
export const deferRenderPhaseUpdateToNextBatch = true;
5353

packages/shared/forks/ReactFeatureFlags.test-renderer.native.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = false;
4848
export const deletedTreeCleanUpLevel = 1;
4949
export const enableSuspenseLayoutEffectSemantics = false;
50-
export const enableGetInspectorDataForInstanceInProduction = false;
50+
5151
export const enableNewReconciler = false;
5252
export const deferRenderPhaseUpdateToNextBatch = true;
5353

packages/shared/forks/ReactFeatureFlags.test-renderer.www.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = false;
4848
export const deletedTreeCleanUpLevel = 1;
4949
export const enableSuspenseLayoutEffectSemantics = false;
50-
export const enableGetInspectorDataForInstanceInProduction = false;
50+
5151
export const enableNewReconciler = false;
5252
export const deferRenderPhaseUpdateToNextBatch = true;
5353

packages/shared/forks/ReactFeatureFlags.testing.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = false;
4848
export const deletedTreeCleanUpLevel = 1;
4949
export const enableSuspenseLayoutEffectSemantics = false;
50-
export const enableGetInspectorDataForInstanceInProduction = false;
50+
5151
export const enableNewReconciler = false;
5252
export const deferRenderPhaseUpdateToNextBatch = true;
5353

packages/shared/forks/ReactFeatureFlags.testing.www.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export const disableNativeComponentFrames = false;
4747
export const skipUnmountedBoundaries = true;
4848
export const deletedTreeCleanUpLevel = 1;
4949
export const enableSuspenseLayoutEffectSemantics = false;
50-
export const enableGetInspectorDataForInstanceInProduction = false;
50+
5151
export const enableNewReconciler = false;
5252
export const deferRenderPhaseUpdateToNextBatch = true;
5353

packages/shared/forks/ReactFeatureFlags.www.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export const warnAboutDeprecatedLifecycles = true;
6060
export const disableLegacyContext = __EXPERIMENTAL__;
6161
export const warnAboutStringRefs = false;
6262
export const warnAboutDefaultPropsOnFunctionComponents = false;
63-
export const enableGetInspectorDataForInstanceInProduction = false;
63+
6464
export const enableSuspenseServerRenderer = true;
6565
export const enableSelectiveHydration = true;
6666

0 commit comments

Comments
 (0)