Add guard to ensure Profiler onRender prop is function before calling (#16197)

This commit is contained in:
Brian Vaughn
2019-07-24 14:20:56 -07:00
committed by GitHub
parent 144dba1a11
commit 9ae5e38f18
2 changed files with 22 additions and 22 deletions
+21 -19
View File
@@ -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},