9
10
import * as React from 'react';
11
import {Fragment, useContext, useEffect, useRef} from 'react';
12
+
13
import WhatChanged from './WhatChanged';
14
import {ProfilerContext} from './ProfilerContext';
15
import {formatDuration, formatTime} from './utils';
16
import {StoreContext} from '../context';
17
import Button from '../Button';
18
import ButtonIcon from '../ButtonIcon';
19
+import InspectedElementBadges from '../Components/InspectedElementBadges';
20
21
import styles from './SidebarSelectedFiberInfo.css';
22
21
-export type Props = {};
22
-
23
-export default function SidebarSelectedFiberInfo(_: Props): React.Node {
23
+export default function SidebarSelectedFiberInfo(): React.Node {
24
const {profilerStore} = useContext(StoreContext);
25
const {
26
rootID,
33
const {profilingCache} = profilerStore;
34
const selectedListItemRef = useRef<HTMLElement | null>(null);
35
36
+ useEffect(() => {
37
+ const selectedElement = selectedListItemRef.current;
38
+ if (
39
+ selectedElement !== null &&
40
+ // $FlowFixMe[method-unbinding]
41
+ typeof selectedElement.scrollIntoView === 'function'
42
+ ) {
43
+ selectedElement.scrollIntoView({block: 'nearest', inline: 'nearest'});
44
+ }
45
+ }, [selectedCommitIndex]);
46
+
47
+ if (
48
+ selectedFiberID === null ||
49
+ rootID === null ||
50
+ selectedCommitIndex === null
51
+ ) {
52
+ return null;
53
+ }
54
+
55
const commitIndices = profilingCache.getFiberCommits({
37
- fiberID: ((selectedFiberID: any): number),
38
- rootID: ((rootID: any): number),
56
+ fiberID: selectedFiberID,
57
+ rootID: rootID,
58
});
59
60
+ const {nodes} = profilingCache.getCommitTree({
61
+ rootID,
62
+ commitIndex: selectedCommitIndex,
63
+ });
64
+ const node = nodes.get(selectedFiberID);
65
+
66
// $FlowFixMe[missing-local-annot]
67
const handleKeyDown = event => {
68
switch (event.key) {
89
}
90
};
91
67
- useEffect(() => {
68
- const selectedElement = selectedListItemRef.current;
69
- if (
70
- selectedElement !== null &&
71
- // $FlowFixMe[method-unbinding]
72
- typeof selectedElement.scrollIntoView === 'function'
73
- ) {
74
- selectedElement.scrollIntoView({block: 'nearest', inline: 'nearest'});
75
- }
76
- }, [selectedCommitIndex]);
77
-
92
const listItems = [];
93
let i = 0;
94
for (i = 0; i < commitIndices.length; i++) {
128
</Button>
129
</div>
130
<div className={styles.Content} onKeyDown={handleKeyDown} tabIndex={0}>
131
+ {node != null && (
132
+ <InspectedElementBadges
133
+ hocDisplayNames={node.hocDisplayNames}
134
+ compiledWithForget={node.compiledWithForget}
135
+ />
136
+ )}
137
<WhatChanged fiberID={((selectedFiberID: any): number)} />
138
{listItems.length > 0 && (
119
- <Fragment>
120
- <label className={styles.Label}>Rendered at</label>: {listItems}
121
- </Fragment>
139
+ <div>
140
+ <label className={styles.Label}>Rendered at: </label>
141
+ {listItems}
142
+ </div>
143
)}
144
{listItems.length === 0 && (
145
<div>Did not render during this profiling session.</div>