Skip to content

Commit 5dfbfe9

Browse files
authored
Fixed debug performance labels for new component types (#12609)
* Added new debug performance tests for AsyncMode, StrictMode, forwardRef, and context provider/consumer components. * Updated performance labels to exclude AsyncMode and StrictMode. * Added labels for forwardRef (and inner function) that mirror DevTools labels.
1 parent c27a998 commit 5dfbfe9

File tree

4 files changed

+120
-0
lines changed

4 files changed

+120
-0
lines changed

packages/react-reconciler/src/ReactDebugFiberPerf.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
Fragment,
2222
ContextProvider,
2323
ContextConsumer,
24+
Mode,
2425
} from 'shared/ReactTypeOfWork';
2526

2627
type MeasurementPhase =
@@ -175,6 +176,7 @@ const shouldIgnoreFiber = (fiber: Fiber): boolean => {
175176
case Fragment:
176177
case ContextProvider:
177178
case ContextConsumer:
179+
case Mode:
178180
return true;
179181
default:
180182
return false;

packages/react-reconciler/src/__tests__/ReactIncrementalPerf-test.internal.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,64 @@ describe('ReactDebugFiberPerf', () => {
161161
expect(getFlameChart()).toMatchSnapshot();
162162
});
163163

164+
it('properly displays the forwardRef component in measurements', () => {
165+
const AnonymousForwardRef = React.forwardRef((props, ref) => (
166+
<Child {...props} ref={ref} />
167+
));
168+
const NamedForwardRef = React.forwardRef(function refForwarder(props, ref) {
169+
return <Child {...props} ref={ref} />;
170+
});
171+
function notImportant(props, ref) {
172+
return <Child {...props} ref={ref} />;
173+
}
174+
notImportant.displayName = 'OverriddenName';
175+
const DisplayNamedForwardRef = React.forwardRef(notImportant);
176+
177+
ReactNoop.render(
178+
<Parent>
179+
<AnonymousForwardRef />
180+
<NamedForwardRef />
181+
<DisplayNamedForwardRef />
182+
</Parent>,
183+
);
184+
addComment('Mount');
185+
ReactNoop.flush();
186+
187+
expect(getFlameChart()).toMatchSnapshot();
188+
});
189+
190+
it('does not include StrictMode or AsyncMode components in measurements', () => {
191+
ReactNoop.render(
192+
<React.StrictMode>
193+
<Parent>
194+
<React.unstable_AsyncMode>
195+
<Child />
196+
</React.unstable_AsyncMode>
197+
</Parent>
198+
</React.StrictMode>,
199+
);
200+
addComment('Mount');
201+
ReactNoop.flush();
202+
203+
expect(getFlameChart()).toMatchSnapshot();
204+
});
205+
206+
it('does not include context provider or consumer in measurements', () => {
207+
const {Consumer, Provider} = React.createContext(true);
208+
209+
ReactNoop.render(
210+
<Provider value={false}>
211+
<Parent>
212+
<Consumer>{value => <Child value={value} />}</Consumer>
213+
</Parent>
214+
</Provider>,
215+
);
216+
addComment('Mount');
217+
ReactNoop.flush();
218+
219+
expect(getFlameChart()).toMatchSnapshot();
220+
});
221+
164222
it('skips parents during setState', () => {
165223
class A extends React.Component {
166224
render() {

packages/react-reconciler/src/__tests__/__snapshots__/ReactIncrementalPerf-test.internal.js.snap

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,36 @@ exports[`ReactDebugFiberPerf deduplicates lifecycle names during commit to reduc
9191
"
9292
`;
9393

94+
exports[`ReactDebugFiberPerf does not include StrictMode or AsyncMode components in measurements 1`] = `
95+
"⚛ (Waiting for async callback... will force flush in 5230 ms)
96+
97+
// Mount
98+
⚛ (React Tree Reconciliation: Completed Root)
99+
⚛ Parent [mount]
100+
⚛ Child [mount]
101+
102+
⚛ (Committing Changes)
103+
⚛ (Committing Snapshot Effects: 0 Total)
104+
⚛ (Committing Host Effects: 1 Total)
105+
⚛ (Calling Lifecycle Methods: 0 Total)
106+
"
107+
`;
108+
109+
exports[`ReactDebugFiberPerf does not include context provider or consumer in measurements 1`] = `
110+
"⚛ (Waiting for async callback... will force flush in 5230 ms)
111+
112+
// Mount
113+
⚛ (React Tree Reconciliation: Completed Root)
114+
⚛ Parent [mount]
115+
⚛ Child [mount]
116+
117+
⚛ (Committing Changes)
118+
⚛ (Committing Snapshot Effects: 0 Total)
119+
⚛ (Committing Host Effects: 1 Total)
120+
⚛ (Calling Lifecycle Methods: 0 Total)
121+
"
122+
`;
123+
94124
exports[`ReactDebugFiberPerf does not schedule an extra callback if setState is called during a synchronous commit phase 1`] = `
95125
"⚛ (React Tree Reconciliation: Completed Root)
96126
⚛ Component [mount]
@@ -231,6 +261,26 @@ exports[`ReactDebugFiberPerf measures deprioritized work 1`] = `
231261
"
232262
`;
233263

264+
exports[`ReactDebugFiberPerf properly displays the forwardRef component in measurements 1`] = `
265+
"⚛ (Waiting for async callback... will force flush in 5230 ms)
266+
267+
// Mount
268+
⚛ (React Tree Reconciliation: Completed Root)
269+
⚛ Parent [mount]
270+
⚛ ForwardRef [mount]
271+
⚛ Child [mount]
272+
⚛ ForwardRef(refForwarder) [mount]
273+
⚛ Child [mount]
274+
⚛ ForwardRef(OverriddenName) [mount]
275+
⚛ Child [mount]
276+
277+
⚛ (Committing Changes)
278+
⚛ (Committing Snapshot Effects: 0 Total)
279+
⚛ (Committing Host Effects: 1 Total)
280+
⚛ (Calling Lifecycle Methods: 0 Total)
281+
"
282+
`;
283+
234284
exports[`ReactDebugFiberPerf recovers from caught errors 1`] = `
235285
"⚛ (Waiting for async callback... will force flush in 5230 ms)
236286

packages/shared/getComponentName.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
REACT_FRAGMENT_TYPE,
1515
REACT_RETURN_TYPE,
1616
REACT_PORTAL_TYPE,
17+
REACT_FORWARD_REF_TYPE,
1718
} from 'shared/ReactSymbols';
1819

1920
function getComponentName(fiber: Fiber): string | null {
@@ -34,6 +35,15 @@ function getComponentName(fiber: Fiber): string | null {
3435
case REACT_RETURN_TYPE:
3536
return 'ReactReturn';
3637
}
38+
if (typeof type === 'object' && type !== null) {
39+
switch (type.$$typeof) {
40+
case REACT_FORWARD_REF_TYPE:
41+
const functionName = type.render.displayName || type.render.name || '';
42+
return functionName !== ''
43+
? `ForwardRef(${functionName})`
44+
: 'ForwardRef';
45+
}
46+
}
3747
return null;
3848
}
3949

0 commit comments

Comments
 (0)