Skip to content

Commit e3530ab

Browse files
committed
show hoc names in profiler
1 parent 6fd4321 commit e3530ab

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

packages/react-devtools-shared/src/devtools/ProfilerStore.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ export default class ProfilerStore extends EventEmitter<{|
211211
id: elementID,
212212
children: element.children.slice(0),
213213
displayName: element.displayName,
214+
hocDisplayNames: element.hocDisplayNames,
214215
key: element.key,
215216
type: element.type,
216217
};

packages/react-devtools-shared/src/devtools/views/Profiler/CommitTreeBuilder.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ function recursivelyInitializeTree(
130130
id,
131131
children: node.children,
132132
displayName: node.displayName,
133+
hocDisplayNames: node.hocDisplayNames,
133134
key: node.key,
134135
parentID,
135136
treeBaseDuration: ((dataForRoot.initialTreeBaseDurations.get(
@@ -208,6 +209,7 @@ function updateTree(
208209
const node: CommitTreeNode = {
209210
children: [],
210211
displayName: null,
212+
hocDisplayNames: null,
211213
id,
212214
key: null,
213215
parentID: 0,
@@ -243,6 +245,7 @@ function updateTree(
243245
const node: CommitTreeNode = {
244246
children: [],
245247
displayName,
248+
hocDisplayNames: null,
246249
id,
247250
key,
248251
parentID,

packages/react-devtools-shared/src/devtools/views/Profiler/FlamegraphChartBuilder.js

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@
77
* @flow
88
*/
99

10-
import {
11-
ElementTypeForwardRef,
12-
ElementTypeMemo,
13-
} from 'react-devtools-shared/src/types';
1410
import {formatDuration} from './utils';
1511
import ProfilerStore from 'react-devtools-shared/src/devtools/ProfilerStore';
1612

@@ -75,7 +71,7 @@ export function getChartData({
7571
throw Error(`Could not find node with id "${id}" in commit tree`);
7672
}
7773

78-
const {children, displayName, key, treeBaseDuration, type} = node;
74+
const {children, displayName, key, treeBaseDuration} = node;
7975

8076
const actualDuration = fiberActualDurations.get(id) || 0;
8177
const selfDuration = fiberSelfDurations.get(id) || 0;
@@ -85,10 +81,8 @@ export function getChartData({
8581
const maybeKey = key !== null ? ` key="${key}"` : '';
8682

8783
let maybeBadge = '';
88-
if (type === ElementTypeForwardRef) {
89-
maybeBadge = ' (ForwardRef)';
90-
} else if (type === ElementTypeMemo) {
91-
maybeBadge = ' (Memo)';
84+
if (node.hocDisplayNames) {
85+
maybeBadge = ` (${node.hocDisplayNames[0]})`;
9286
}
9387

9488
let label = `${name}${maybeBadge}${maybeKey}`;

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export type CommitTreeNode = {|
1313
id: number,
1414
children: Array<number>,
1515
displayName: string | null,
16+
hocDisplayNames: Array<string> | null,
1617
key: number | string | null,
1718
parentID: number,
1819
treeBaseDuration: number,
@@ -34,6 +35,7 @@ export type SnapshotNode = {|
3435
id: number,
3536
children: Array<number>,
3637
displayName: string | null,
38+
hocDisplayNames: Array<string> | null,
3739
key: number | string | null,
3840
type: ElementType,
3941
|};

packages/react-devtools-shell/src/app/InspectableElements/CustomHooks.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,24 @@ function FunctionWithHooks(props: any, ref: React$Ref<any>) {
9393
const MemoWithHooks = memo(FunctionWithHooks);
9494
const ForwardRefWithHooks = forwardRef(FunctionWithHooks);
9595

96+
function wrapWithHoc(Component) {
97+
function Hoc() {
98+
return <Component />;
99+
}
100+
// $FlowFixMe
101+
const displayName = Component.displayName || Component.name;
102+
Hoc.displayName = `withHoc(${displayName})`;
103+
return Hoc;
104+
}
105+
const HocWithHooks = wrapWithHoc(FunctionWithHooks);
106+
96107
export default function CustomHooks() {
97108
return (
98109
<Fragment>
99110
<FunctionWithHooks />
100111
<MemoWithHooks />
101112
<ForwardRefWithHooks />
113+
<HocWithHooks />
102114
</Fragment>
103115
);
104116
}

0 commit comments

Comments
 (0)