Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2b9d7cf

Browse files
karlhorkybvaughn
andauthored
Devtools: Show inspectedElement key in right pane (facebook#18737)
* 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]>
1 parent ddcc69c commit 2b9d7cf

File tree

7 files changed

+46
-1
lines changed

7 files changed

+46
-1
lines changed

packages/react-devtools-shared/src/backend/legacy/renderer.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -731,7 +731,7 @@ export function attach(
731731
return null;
732732
}
733733

734-
const {displayName} = getData(internalInstance);
734+
const {displayName, key} = getData(internalInstance);
735735
const type = getElementType(internalInstance);
736736

737737
let context = null;
@@ -789,6 +789,8 @@ export function attach(
789789

790790
type: type,
791791

792+
key: key != null ? key : null,
793+
792794
// Inspectable properties.
793795
context,
794796
hooks: null,

packages/react-devtools-shared/src/backend/renderer.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2143,6 +2143,7 @@ export function attach(
21432143
_debugOwner,
21442144
_debugSource,
21452145
stateNode,
2146+
key,
21462147
memoizedProps,
21472148
memoizedState,
21482149
tag,
@@ -2300,6 +2301,8 @@ export function attach(
23002301
// Does the component have legacy context attached to it.
23012302
hasLegacyContext,
23022303

2304+
key: key != null ? key : null,
2305+
23032306
displayName: getDisplayNameForFiber(fiber),
23042307
type: elementType,
23052308

packages/react-devtools-shared/src/backend/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ export type InspectedElement = {|
202202
hooks: Object | null,
203203
props: Object | null,
204204
state: Object | null,
205+
key: number | string | null,
205206

206207
// List of owners
207208
owners: Array<Owner> | null,

packages/react-devtools-shared/src/devtools/views/Components/InspectedElementContext.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ function InspectedElementContextController({children}: Props) {
209209
hooks,
210210
props,
211211
state,
212+
key,
212213
} = ((data.value: any): InspectedElementBackend);
213214

214215
const inspectedElement: InspectedElementFrontend = {
@@ -218,6 +219,7 @@ function InspectedElementContextController({children}: Props) {
218219
canViewSource,
219220
hasLegacyContext,
220221
id,
222+
key,
221223
source,
222224
type,
223225
owners:

packages/react-devtools-shared/src/devtools/views/Components/SelectedElement.css

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,37 @@
1616
padding: 0.5rem;
1717
}
1818

19+
.Key {
20+
flex: 0 1 auto;
21+
padding-left: 0.25rem;
22+
padding-right: 0.125rem;
23+
line-height: 1rem;
24+
border-top-left-radius: 0.125rem;
25+
border-bottom-left-radius: 0.125rem;
26+
display: inline-block;
27+
background-color: var(--color-component-badge-background);
28+
color: var(--color-text);
29+
font-family: var(--font-family-monospace);
30+
font-size: var(--font-size-monospace-small);
31+
white-space: nowrap;
32+
overflow: hidden;
33+
text-overflow: ellipsis;
34+
max-width: 100%;
35+
}
36+
37+
.KeyArrow {
38+
height: 1rem;
39+
width: 1rem;
40+
margin-right: -0.25rem;
41+
border: 0.5rem solid transparent;
42+
border-left: 0.5rem solid var(--color-component-badge-background);
43+
}
44+
1945
.SelectedComponentName {
2046
flex: 1 1 auto;
2147
overflow: hidden;
2248
text-overflow: ellipsis;
49+
line-height: normal;
2350
}
2451

2552
.Owners {

packages/react-devtools-shared/src/devtools/views/Components/SelectedElement.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ export default function SelectedElement(_: Props) {
190190
return (
191191
<div className={styles.SelectedElement}>
192192
<div className={styles.TitleRow}>
193+
{element.key && (
194+
<>
195+
<div className={styles.Key} title={`key "${element.key}"`}>
196+
{element.key}
197+
</div>
198+
<div className={styles.KeyArrow} />
199+
</>
200+
)}
201+
193202
<div className={styles.SelectedComponentName}>
194203
<div className={styles.Component} title={element.displayName}>
195204
{element.displayName}

packages/react-devtools-shared/src/devtools/views/Components/types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ export type InspectedElement = {|
7979
hooks: Object | null,
8080
props: Object | null,
8181
state: Object | null,
82+
key: number | string | null,
8283

8384
// List of owners
8485
owners: Array<Owner> | null,

0 commit comments

Comments
 (0)