Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Devtools: Show inspectedElement key in right pane #18737

Merged
merged 9 commits into from
May 11, 2020
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -731,7 +731,7 @@ export function attach(
return null;
}

const {displayName} = getData(internalInstance);
const {displayName, key} = getData(internalInstance);
const type = getElementType(internalInstance);

let context = null;
Expand Down Expand Up @@ -789,6 +789,8 @@ export function attach(

type: type,

key: key != null ? key : null,

// Inspectable properties.
context,
hooks: null,
Expand Down
3 changes: 3 additions & 0 deletions packages/react-devtools-shared/src/backend/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,7 @@ export function attach(
_debugOwner,
_debugSource,
stateNode,
key,
memoizedProps,
memoizedState,
tag,
Expand Down Expand Up @@ -2300,6 +2301,8 @@ export function attach(
// Does the component have legacy context attached to it.
hasLegacyContext,

key: key != null ? key : null,

displayName: getDisplayNameForFiber(fiber),
type: elementType,

Expand Down
1 change: 1 addition & 0 deletions packages/react-devtools-shared/src/backend/types.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ export type InspectedElement = {|
hooks: Object | null,
props: Object | null,
state: Object | null,
key: number | string | null,

// List of owners
owners: Array<Owner> | null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,7 @@ function InspectedElementContextController({children}: Props) {
hooks,
props,
state,
key,
} = ((data.value: any): InspectedElementBackend);

const inspectedElement: InspectedElementFrontend = {
Expand All @@ -218,6 +219,7 @@ function InspectedElementContextController({children}: Props) {
canViewSource,
hasLegacyContext,
id,
key,
source,
type,
owners:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,16 @@ export default function InspectedElementTree({
} else {
return (
<div className={styles.InspectedElementTree}>
<div className={styles.HeaderRow}>
<div className={styles.Header}>{label}</div>
{!isEmpty && (
<Button onClick={handleCopy} title="Copy to clipboard">
<ButtonIcon type="copy" />
</Button>
)}
</div>
{label && (
<div className={styles.HeaderRow}>
<div className={styles.Header}>{label}</div>
{!isEmpty && (
<Button onClick={handleCopy} title="Copy to clipboard">
<ButtonIcon type="copy" />
</Button>
)}
</div>
)}
{isEmpty && !canAddEntries && <div className={styles.Empty}>None</div>}
{!isEmpty &&
(entries: any).map(([name, value]) => (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ function InspectedElementView({
props,
source,
state,
key,
} = inspectedElement;

const {ownerID} = useContext(TreeStateContext);
Expand All @@ -301,6 +302,12 @@ function InspectedElementView({
},
[getInspectedElementPath, id],
);
const inspectKeyPath = useCallback(
(path: Array<string | number>) => {
getInspectedElementPath(id, ['key', ...path]);
},
[getInspectedElementPath, id],
);
const inspectPropsPath = useCallback(
(path: Array<string | number>) => {
getInspectedElementPath(id, ['props', ...path]);
Expand Down Expand Up @@ -369,6 +376,14 @@ function InspectedElementView({
<Fragment>
<div className={styles.InspectedElement}>
<HocBadges element={element} />
{key && (
<InspectedElementTree
label=""
data={{key: key}}
inspectPath={inspectKeyPath}
pathRoot="key"
/>
)}
<InspectedElementTree
label="props"
data={props}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export type InspectedElement = {|
hooks: Object | null,
props: Object | null,
state: Object | null,
key: number | string | null,

// List of owners
owners: Array<Owner> | null,
Expand Down