Skip to content

Commit 74ea0c7

Browse files
authored
Remove enableGetInspectorDataForInstanceInProduction flag (#32033)
## Summary Callers for this method has been removed in facebook/react-native@65bda54, so these methods no longer need to be conditionally exported and the feature flag can be removed. ## How did you test this change? Flow fabric/native
1 parent 1506685 commit 74ea0c7

10 files changed

+61
-87
lines changed

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ import {
2929
import {createPortal as createPortalImpl} from 'react-reconciler/src/ReactPortal';
3030
import {setBatchingImplementation} from './legacy-events/ReactGenericBatching';
3131

32-
import {getInspectorDataForInstance} from './ReactNativeFiberInspector';
3332
import {LegacyRoot, ConcurrentRoot} from 'react-reconciler/src/ReactRootTags';
3433
import {
3534
findHostInstance_DEPRECATED,
@@ -188,9 +187,6 @@ export {
188187
unmountComponentAtNode,
189188
stopSurface,
190189
createPortal,
191-
// This export is typically undefined in production builds.
192-
// See the "enableGetInspectorDataForInstanceInProduction" flag.
193-
getInspectorDataForInstance,
194190
// The public instance has a reference to the internal instance handle.
195191
// This method allows it to acess the most recent shadow node for
196192
// the instance (it's only accessible through it).

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

Lines changed: 61 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -21,47 +21,47 @@ import {
2121
UIManager,
2222
getNodeFromPublicInstance,
2323
} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
24-
import {enableGetInspectorDataForInstanceInProduction} from 'shared/ReactFeatureFlags';
2524
import {getClosestInstanceFromNode} from './ReactNativeComponentTree';
2625
import {
2726
getNodeFromInternalInstanceHandle,
2827
findNodeHandle,
2928
} from './ReactNativePublicCompat';
3029
import {getStackByFiberInDevAndProd} from 'react-reconciler/src/ReactFiberComponentStack';
3130

32-
const emptyObject = {};
31+
let getInspectorDataForInstance: (
32+
closestInstance: Fiber | null,
33+
) => InspectorData;
34+
3335
if (__DEV__) {
34-
Object.freeze(emptyObject);
35-
}
36+
const emptyObject = Object.freeze({});
3637

37-
// $FlowFixMe[missing-local-annot]
38-
function createHierarchy(fiberHierarchy) {
39-
return fiberHierarchy.map(fiber => ({
40-
name: getComponentNameFromType(fiber.type),
41-
getInspectorData: () => {
42-
return {
43-
props: getHostProps(fiber),
44-
measure: callback => {
45-
// If this is Fabric, we'll find a shadow node and use that to measure.
46-
const hostFiber = findCurrentHostFiber(fiber);
47-
const node =
48-
hostFiber != null &&
49-
hostFiber.stateNode !== null &&
50-
hostFiber.stateNode.node;
38+
// $FlowFixMe[missing-local-annot]
39+
const createHierarchy = function (fiberHierarchy) {
40+
return fiberHierarchy.map(fiber => ({
41+
name: getComponentNameFromType(fiber.type),
42+
getInspectorData: () => {
43+
return {
44+
props: getHostProps(fiber),
45+
measure: callback => {
46+
// If this is Fabric, we'll find a shadow node and use that to measure.
47+
const hostFiber = findCurrentHostFiber(fiber);
48+
const node =
49+
hostFiber != null &&
50+
hostFiber.stateNode !== null &&
51+
hostFiber.stateNode.node;
5152

52-
if (node) {
53-
nativeFabricUIManager.measure(node, callback);
54-
} else {
55-
return UIManager.measure(getHostNode(fiber), callback);
56-
}
57-
},
58-
};
59-
},
60-
}));
61-
}
53+
if (node) {
54+
nativeFabricUIManager.measure(node, callback);
55+
} else {
56+
return UIManager.measure(getHostNode(fiber), callback);
57+
}
58+
},
59+
};
60+
},
61+
}));
62+
};
6263

63-
function getHostNode(fiber: Fiber | null) {
64-
if (__DEV__ || enableGetInspectorDataForInstanceInProduction) {
64+
const getHostNode = function (fiber: Fiber | null) {
6565
let hostNode;
6666
// look for children first for the hostNode
6767
// as composite fibers do not have a hostNode
@@ -75,22 +75,19 @@ function getHostNode(fiber: Fiber | null) {
7575
fiber = fiber.child;
7676
}
7777
return null;
78-
}
79-
}
78+
};
8079

81-
// $FlowFixMe[missing-local-annot]
82-
function getHostProps(fiber) {
83-
const host = findCurrentHostFiber(fiber);
84-
if (host) {
85-
return host.memoizedProps || emptyObject;
86-
}
87-
return emptyObject;
88-
}
80+
const getHostProps = function (fiber: Fiber) {
81+
const host = findCurrentHostFiber(fiber);
82+
if (host) {
83+
return host.memoizedProps || emptyObject;
84+
}
85+
return emptyObject;
86+
};
8987

90-
function getInspectorDataForInstance(
91-
closestInstance: Fiber | null,
92-
): InspectorData {
93-
if (__DEV__ || enableGetInspectorDataForInstanceInProduction) {
88+
getInspectorDataForInstance = function (
89+
closestInstance: Fiber | null,
90+
): InspectorData {
9491
// Handle case where user clicks outside of ReactNative
9592
if (!closestInstance) {
9693
return {
@@ -125,50 +122,43 @@ function getInspectorDataForInstance(
125122
selectedIndex,
126123
componentStack,
127124
};
128-
}
125+
};
129126

130-
throw new Error(
131-
'getInspectorDataForInstance() is not available in production',
132-
);
133-
}
134-
135-
function getOwnerHierarchy(instance: Fiber) {
136-
const hierarchy: Array<$FlowFixMe> = [];
137-
traverseOwnerTreeUp(hierarchy, instance);
138-
return hierarchy;
139-
}
127+
const getOwnerHierarchy = function (instance: Fiber) {
128+
const hierarchy: Array<$FlowFixMe> = [];
129+
traverseOwnerTreeUp(hierarchy, instance);
130+
return hierarchy;
131+
};
140132

141-
// $FlowFixMe[missing-local-annot]
142-
function lastNonHostInstance(hierarchy) {
143-
for (let i = hierarchy.length - 1; i > 1; i--) {
144-
const instance = hierarchy[i];
133+
// $FlowFixMe[missing-local-annot]
134+
const lastNonHostInstance = function (hierarchy) {
135+
for (let i = hierarchy.length - 1; i > 1; i--) {
136+
const instance = hierarchy[i];
145137

146-
if (instance.tag !== HostComponent) {
147-
return instance;
138+
if (instance.tag !== HostComponent) {
139+
return instance;
140+
}
148141
}
149-
}
150-
return hierarchy[0];
151-
}
142+
return hierarchy[0];
143+
};
152144

153-
function traverseOwnerTreeUp(
154-
hierarchy: Array<$FlowFixMe>,
155-
instance: Fiber,
156-
): void {
157-
if (__DEV__ || enableGetInspectorDataForInstanceInProduction) {
145+
const traverseOwnerTreeUp = function (
146+
hierarchy: Array<$FlowFixMe>,
147+
instance: Fiber,
148+
): void {
158149
hierarchy.unshift(instance);
159150
const owner = instance._debugOwner;
160151
if (owner != null && typeof owner.tag === 'number') {
161152
traverseOwnerTreeUp(hierarchy, (owner: any));
162153
} else {
163154
// TODO: Traverse Server Components owners.
164155
}
165-
}
156+
};
166157
}
167158

168159
function getInspectorDataForViewTag(viewTag: number): InspectorData {
169160
if (__DEV__) {
170161
const closestInstance = getClosestInstanceFromNode(viewTag);
171-
172162
return getInspectorDataForInstance(closestInstance);
173163
} else {
174164
throw new Error(

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ import {
3434
// Modules provided by RN:
3535
import {UIManager} from 'react-native/Libraries/ReactPrivate/ReactNativePrivateInterface';
3636

37-
import {getInspectorDataForInstance} from './ReactNativeFiberInspector';
3837
import {LegacyRoot} from 'react-reconciler/src/ReactRootTags';
3938
import {
4039
findHostInstance_DEPRECATED,
@@ -206,9 +205,6 @@ export {
206205
unmountComponentAtNodeAndRemoveContainer,
207206
createPortal,
208207
batchedUpdates as unstable_batchedUpdates,
209-
// This export is typically undefined in production builds.
210-
// See the "enableGetInspectorDataForInstanceInProduction" flag.
211-
getInspectorDataForInstance,
212208
// DEV-only:
213209
isChildPublicInstance,
214210
};

packages/shared/ReactFeatureFlags.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,4 @@ export const enableAsyncDebugInfo = __EXPERIMENTAL__;
260260
export const enableUpdaterTracking = __PROFILE__;
261261

262262
// Internal only.
263-
export const enableGetInspectorDataForInstanceInProduction = false;
264-
265263
export const enableDO_NOT_USE_disableStrictPassiveEffect = false;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ export const enableCreateEventHandleAPI = false;
4848
export const enableDO_NOT_USE_disableStrictPassiveEffect = false;
4949
export const enableMoveBefore = true;
5050
export const enableFizzExternalRuntime = true;
51-
export const enableGetInspectorDataForInstanceInProduction = true;
5251
export const enableHalt = false;
5352
export const enableInfiniteRenderLoopDetection = false;
5453
export const enableLegacyCache = false;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ export const enableDO_NOT_USE_disableStrictPassiveEffect = false;
3333
export const enableFabricCompleteRootInCommitPhase = false;
3434
export const enableMoveBefore = true;
3535
export const enableFizzExternalRuntime = true;
36-
export const enableGetInspectorDataForInstanceInProduction = false;
3736
export const enableHalt = false;
3837
export const enableHiddenSubtreeInsertionEffectCleanup = false;
3938
export const enableInfiniteRenderLoopDetection = false;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ export const enableUseEffectEventHook = false;
3636
export const favorSafetyOverHydrationPerf = true;
3737
export const enableLegacyFBSupport = false;
3838
export const enableMoveBefore = false;
39-
export const enableGetInspectorDataForInstanceInProduction = false;
4039
export const enableFabricCompleteRootInCommitPhase = false;
4140
export const enableHiddenSubtreeInsertionEffectCleanup = false;
4241
export const enableHydrationLaneScheduling = true;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ export const enableCreateEventHandleAPI = false;
2727
export const enableDO_NOT_USE_disableStrictPassiveEffect = false;
2828
export const enableMoveBefore = false;
2929
export const enableFizzExternalRuntime = true;
30-
export const enableGetInspectorDataForInstanceInProduction = false;
3130
export const enableHalt = false;
3231
export const enableInfiniteRenderLoopDetection = false;
3332
export const enableHiddenSubtreeInsertionEffectCleanup = true;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ export const enableUseEffectEventHook = false;
3838
export const favorSafetyOverHydrationPerf = true;
3939
export const enableLegacyFBSupport = false;
4040
export const enableMoveBefore = false;
41-
export const enableGetInspectorDataForInstanceInProduction = false;
4241
export const enableRenderableContext = false;
4342
export const enableFabricCompleteRootInCommitPhase = false;
4443
export const enableHiddenSubtreeInsertionEffectCleanup = true;

packages/shared/forks/ReactFeatureFlags.www.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export const enableSchedulingProfiler: boolean =
6969
__PROFILE__ && dynamicFeatureFlags.enableSchedulingProfiler;
7070

7171
export const disableLegacyContext = __EXPERIMENTAL__;
72-
export const enableGetInspectorDataForInstanceInProduction = false;
7372

7473
export const enableLegacyCache = true;
7574

0 commit comments

Comments
 (0)