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

Fixed debug performance labels for new component types #12609

Merged
merged 6 commits into from
Apr 12, 2018
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
2 changes: 2 additions & 0 deletions packages/react-reconciler/src/ReactDebugFiberPerf.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
Fragment,
ContextProvider,
ContextConsumer,
Mode,
} from 'shared/ReactTypeOfWork';

type MeasurementPhase =
Expand Down Expand Up @@ -175,6 +176,7 @@ const shouldIgnoreFiber = (fiber: Fiber): boolean => {
case Fragment:
case ContextProvider:
case ContextConsumer:
case Mode:
return true;
default:
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,64 @@ describe('ReactDebugFiberPerf', () => {
expect(getFlameChart()).toMatchSnapshot();
});

it('properly displays the forwardRef component in measurements', () => {
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(
<Parent>
<AnonymousForwardRef />
<NamedForwardRef />
<DisplayNamedForwardRef />
</Parent>,
);
addComment('Mount');
ReactNoop.flush();

expect(getFlameChart()).toMatchSnapshot();
});

it('does not include StrictMode or AsyncMode components in measurements', () => {
ReactNoop.render(
<React.StrictMode>
<Parent>
<React.unstable_AsyncMode>
<Child />
</React.unstable_AsyncMode>
</Parent>
</React.StrictMode>,
);
addComment('Mount');
ReactNoop.flush();

expect(getFlameChart()).toMatchSnapshot();
});

it('does not include context provider or consumer in measurements', () => {
const {Consumer, Provider} = React.createContext(true);

ReactNoop.render(
<Provider value={false}>
<Parent>
<Consumer>{value => <Child value={value} />}</Consumer>
</Parent>
</Provider>,
);
addComment('Mount');
ReactNoop.flush();

expect(getFlameChart()).toMatchSnapshot();
});

it('skips parents during setState', () => {
class A extends React.Component {
render() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,36 @@ exports[`ReactDebugFiberPerf deduplicates lifecycle names during commit to reduc
"
`;

exports[`ReactDebugFiberPerf does not include StrictMode or AsyncMode components in measurements 1`] = `
"⚛ (Waiting for async callback... will force flush in 5230 ms)

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

⚛ (Committing Changes)
⚛ (Committing Snapshot Effects: 0 Total)
⚛ (Committing Host Effects: 1 Total)
⚛ (Calling Lifecycle Methods: 0 Total)
"
`;

exports[`ReactDebugFiberPerf does not include context provider or consumer in measurements 1`] = `
"⚛ (Waiting for async callback... will force flush in 5230 ms)

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

⚛ (Committing Changes)
⚛ (Committing Snapshot Effects: 0 Total)
⚛ (Committing Host Effects: 1 Total)
⚛ (Calling Lifecycle Methods: 0 Total)
"
`;

exports[`ReactDebugFiberPerf does not schedule an extra callback if setState is called during a synchronous commit phase 1`] = `
"⚛ (React Tree Reconciliation: Completed Root)
⚛ Component [mount]
Expand Down Expand Up @@ -231,6 +261,26 @@ exports[`ReactDebugFiberPerf measures deprioritized work 1`] = `
"
`;

exports[`ReactDebugFiberPerf properly displays the forwardRef component in measurements 1`] = `
"⚛ (Waiting for async callback... will force flush in 5230 ms)

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

⚛ (Committing Changes)
⚛ (Committing Snapshot Effects: 0 Total)
⚛ (Committing Host Effects: 1 Total)
⚛ (Calling Lifecycle Methods: 0 Total)
"
`;

exports[`ReactDebugFiberPerf recovers from caught errors 1`] = `
"⚛ (Waiting for async callback... will force flush in 5230 ms)

Expand Down
10 changes: 10 additions & 0 deletions packages/shared/getComponentName.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
REACT_FRAGMENT_TYPE,
REACT_RETURN_TYPE,
REACT_PORTAL_TYPE,
REACT_FORWARD_REF_TYPE,
} from 'shared/ReactSymbols';

function getComponentName(fiber: Fiber): string | null {
Expand All @@ -34,6 +35,15 @@ function getComponentName(fiber: Fiber): string | null {
case REACT_RETURN_TYPE:
return 'ReactReturn';
}
if (typeof type === 'object' && type !== null) {
switch (type.$$typeof) {
case REACT_FORWARD_REF_TYPE:
const functionName = type.render.displayName || type.render.name || '';
return functionName !== ''
? `ForwardRef(${functionName})`
: 'ForwardRef';
}
}
return null;
}

Expand Down