Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Added forwardRef function name support to perf label
  • Loading branch information
bvaughn committed Apr 12, 2018
commit 0cc677aea85277dfa4e6a0bd489526f4ddfa78f3
Original file line number Diff line number Diff line change
Expand Up @@ -162,11 +162,25 @@ describe('ReactDebugFiberPerf', () => {
});

it('properly displays the forwardRef component in measurements', () => {
const ForwardRef = React.forwardRef(function refForwarder(props, ref) {
const AnonymousForwardRef = React.forwardRef((props, ref) => (
<Child {...props} ref={ref} />
));
const NamedForwardRef = React.forwardRef(function refForwarder(props, ref) {
return <Child {...props} ref={ref} />;
});
function notImportant(props, ref) {
return <Child {...props} ref={ref} />;
}
notImportant.displayName = 'OverriddenName';
const DisplayNamedForwardRef = React.forwardRef(notImportant);

ReactNoop.render(<ForwardRef />);
ReactNoop.render(
<Parent>
<AnonymousForwardRef />
<NamedForwardRef />
<DisplayNamedForwardRef />
</Parent>,
);
addComment('Mount');
ReactNoop.flush();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,13 @@ exports[`ReactDebugFiberPerf properly displays the forwardRef component in measu

// Mount
⚛ (React Tree Reconciliation: Completed Root)
⚛ ForwardRef [mount]
⚛ Child [mount]
⚛ Parent [mount]
⚛ ForwardRef [mount]
⚛ Child [mount]
⚛ ForwardRef(refForwarder) [mount]
⚛ Child [mount]
⚛ ForwardRef(OverriddenName) [mount]
⚛ Child [mount]

⚛ (Committing Changes)
⚛ (Committing Snapshot Effects: 0 Total)
Expand Down
6 changes: 5 additions & 1 deletion packages/shared/getComponentName.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,11 @@ function getComponentName(fiber: Fiber): string | null {
if (typeof type === 'object' && type !== null) {
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE:
return 'ForwardRef';
const functionName =
type.render.displayName || type.render.name || '';
return functionName !== ''
? `ForwardRef(${functionName})`
: 'ForwardRef';
}
}
return null;
Expand Down