mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Add guard to ensure Profiler onRender prop is function before calling (#16197)
This commit is contained in:
+21
-19
@@ -567,25 +567,27 @@ function commitLifeCycles(
|
||||
if (enableProfilerTimer) {
|
||||
const onRender = finishedWork.memoizedProps.onRender;
|
||||
|
||||
if (enableSchedulerTracing) {
|
||||
onRender(
|
||||
finishedWork.memoizedProps.id,
|
||||
current === null ? 'mount' : 'update',
|
||||
finishedWork.actualDuration,
|
||||
finishedWork.treeBaseDuration,
|
||||
finishedWork.actualStartTime,
|
||||
getCommitTime(),
|
||||
finishedRoot.memoizedInteractions,
|
||||
);
|
||||
} else {
|
||||
onRender(
|
||||
finishedWork.memoizedProps.id,
|
||||
current === null ? 'mount' : 'update',
|
||||
finishedWork.actualDuration,
|
||||
finishedWork.treeBaseDuration,
|
||||
finishedWork.actualStartTime,
|
||||
getCommitTime(),
|
||||
);
|
||||
if (typeof onRender === 'function') {
|
||||
if (enableSchedulerTracing) {
|
||||
onRender(
|
||||
finishedWork.memoizedProps.id,
|
||||
current === null ? 'mount' : 'update',
|
||||
finishedWork.actualDuration,
|
||||
finishedWork.treeBaseDuration,
|
||||
finishedWork.actualStartTime,
|
||||
getCommitTime(),
|
||||
finishedRoot.memoizedInteractions,
|
||||
);
|
||||
} else {
|
||||
onRender(
|
||||
finishedWork.memoizedProps.id,
|
||||
current === null ? 'mount' : 'update',
|
||||
finishedWork.actualDuration,
|
||||
finishedWork.treeBaseDuration,
|
||||
finishedWork.actualStartTime,
|
||||
getCommitTime(),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
return;
|
||||
|
||||
@@ -126,9 +126,7 @@ describe('Profiler', () => {
|
||||
if (__DEV__ && enableProfilerTimer) {
|
||||
it('should warn if required params are missing', () => {
|
||||
expect(() => {
|
||||
expect(() => {
|
||||
ReactTestRenderer.create(<React.Profiler />);
|
||||
}).toThrow('onRender is not a function');
|
||||
ReactTestRenderer.create(<React.Profiler />);
|
||||
}).toWarnDev(
|
||||
'Profiler must specify an "id" string and "onRender" function as props',
|
||||
{withoutStack: true},
|
||||
|
||||
Reference in New Issue
Block a user