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 HOC names in profiler #19283

Merged
merged 2 commits into from
Jul 10, 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 @@ -211,6 +211,7 @@ export default class ProfilerStore extends EventEmitter<{|
id: elementID,
children: element.children.slice(0),
displayName: element.displayName,
hocDisplayNames: element.hocDisplayNames,
key: element.key,
type: element.type,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ function recursivelyInitializeTree(
id,
children: node.children,
displayName: node.displayName,
hocDisplayNames: node.hocDisplayNames,
key: node.key,
parentID,
treeBaseDuration: ((dataForRoot.initialTreeBaseDurations.get(
Expand Down Expand Up @@ -208,6 +209,7 @@ function updateTree(
const node: CommitTreeNode = {
children: [],
displayName: null,
hocDisplayNames: null,
id,
key: null,
parentID: 0,
Expand Down Expand Up @@ -243,6 +245,7 @@ function updateTree(
const node: CommitTreeNode = {
children: [],
displayName,
hocDisplayNames: null,
id,
key,
parentID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@
* @flow
*/

import {
ElementTypeForwardRef,
ElementTypeMemo,
} from 'react-devtools-shared/src/types';
import {formatDuration} from './utils';
import ProfilerStore from 'react-devtools-shared/src/devtools/ProfilerStore';

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

const {children, displayName, key, treeBaseDuration, type} = node;
const {
children,
displayName,
hocDisplayNames,
key,
treeBaseDuration,
} = node;

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

let maybeBadge = '';
if (type === ElementTypeForwardRef) {
maybeBadge = ' (ForwardRef)';
} else if (type === ElementTypeMemo) {
maybeBadge = ' (Memo)';
if (hocDisplayNames !== null && hocDisplayNames.length > 0) {
maybeBadge = ` (${hocDisplayNames[0]})`;
}

let label = `${name}${maybeBadge}${maybeKey}`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type CommitTreeNode = {|
id: number,
children: Array<number>,
displayName: string | null,
hocDisplayNames: Array<string> | null,
key: number | string | null,
parentID: number,
treeBaseDuration: number,
Expand All @@ -34,6 +35,7 @@ export type SnapshotNode = {|
id: number,
children: Array<number>,
displayName: string | null,
hocDisplayNames: Array<string> | null,
key: number | string | null,
type: ElementType,
|};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,24 @@ function FunctionWithHooks(props: any, ref: React$Ref<any>) {
const MemoWithHooks = memo(FunctionWithHooks);
const ForwardRefWithHooks = forwardRef(FunctionWithHooks);

function wrapWithHoc(Component) {
function Hoc() {
return <Component />;
}
// $FlowFixMe
const displayName = Component.displayName || Component.name;
Hoc.displayName = `withHoc(${displayName})`;
return Hoc;
}
const HocWithHooks = wrapWithHoc(FunctionWithHooks);

export default function CustomHooks() {
return (
<Fragment>
<FunctionWithHooks />
<MemoWithHooks />
<ForwardRefWithHooks />
<HocWithHooks />
</Fragment>
);
}
Expand Down