Skip to content

Commit

Permalink
Devtools: Show inspectedElement key in right pane (#18737)
Browse files Browse the repository at this point in the history
* Start MVP for showing inspected element key

* Add key in other places

* Add key from backend

* Remove unnecessary hydrateHelper call

* Hide copy button when no label

* Move above props

* Revert changes to InspectedElementTree.js

* Move key to left of component name

* Updated CSS

Co-authored-by: Brian Vaughn <[email protected]>
  • Loading branch information
karlhorky and bvaughn authored May 11, 2020
1 parent ddcc69c commit 2b9d7cf
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 1 deletion.
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

0 comments on commit 2b9d7cf

Please sign in to comment.