Skip to content

Commit

Permalink
Add componentStack to ReactNativeInspector data
Browse files Browse the repository at this point in the history
This is fairly lazy in that only the selected instance calls this so
the slow component stack call is ok.
  • Loading branch information
sebmarkbage committed Feb 7, 2024
1 parent 6bb9cb4 commit 5354d85
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import {
import {enableGetInspectorDataForInstanceInProduction} from 'shared/ReactFeatureFlags';
import {getClosestInstanceFromNode} from './ReactNativeComponentTree';
import {getNodeFromInternalInstanceHandle} from './ReactNativePublicCompat';
import {getStackByFiberInDevAndProd} from 'react-reconciler/src/ReactFiberComponentStack';

const emptyObject = {};
if (__DEV__) {
Expand Down Expand Up @@ -97,6 +98,7 @@ function getInspectorDataForInstance(
hierarchy: [],
props: emptyObject,
selectedIndex: null,
componentStack: '',
};
}

Expand All @@ -106,12 +108,14 @@ function getInspectorDataForInstance(
const hierarchy = createHierarchy(fiberHierarchy);
const props = getHostProps(instance);
const selectedIndex = fiberHierarchy.indexOf(instance);
const componentStack = fiber !== null ? getStackByFiberInDevAndProd(fiber) : '';

return {
closestInstance: instance,
hierarchy,
props,
selectedIndex,
componentStack,
};
}

Expand Down
1 change: 1 addition & 0 deletions packages/react-native-renderer/src/ReactNativeTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ export type InspectorData = $ReadOnly<{
}>,
selectedIndex: ?number,
props: InspectorDataProps,
componentStack: string,
}>;

export type TouchedViewDataAtPoint = $ReadOnly<{
Expand Down

0 comments on commit 5354d85

Please sign in to comment.