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 all 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 @@ -16,10 +16,37 @@
padding: 0.5rem;
}

.Key {
flex: 0 1 auto;
padding-left: 0.25rem;
padding-right: 0.125rem;
line-height: 1rem;
border-top-left-radius: 0.125rem;
border-bottom-left-radius: 0.125rem;
display: inline-block;
background-color: var(--color-component-badge-background);
color: var(--color-text);
font-family: var(--font-family-monospace);
font-size: var(--font-size-monospace-small);
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
max-width: 100%;
}

.KeyArrow {
height: 1rem;
width: 1rem;
margin-right: -0.25rem;
border: 0.5rem solid transparent;
border-left: 0.5rem solid var(--color-component-badge-background);
}

.SelectedComponentName {
flex: 1 1 auto;
overflow: hidden;
text-overflow: ellipsis;
line-height: normal;
}

.Owners {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,15 @@ export default function SelectedElement(_: Props) {
return (
<div className={styles.SelectedElement}>
<div className={styles.TitleRow}>
{element.key && (
<>
<div className={styles.Key} title={`key "${element.key}"`}>
{element.key}
</div>
<div className={styles.KeyArrow} />
</>
)}

<div className={styles.SelectedComponentName}>
<div className={styles.Component} title={element.displayName}>
{element.displayName}
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