From 9ae5e38f18b6e27dcddc7ecdfc38eefd678c095a Mon Sep 17 00:00:00 2001 From: Brian Vaughn Date: Wed, 24 Jul 2019 14:20:56 -0700 Subject: [PATCH] Add guard to ensure Profiler onRender prop is function before calling (#16197) --- .../src/ReactFiberCommitWork.js | 40 ++++++++++--------- .../__tests__/ReactProfiler-test.internal.js | 4 +- 2 files changed, 22 insertions(+), 22 deletions(-) diff --git a/packages/react-reconciler/src/ReactFiberCommitWork.js b/packages/react-reconciler/src/ReactFiberCommitWork.js index 6009ca50c237a..d840173c1195f 100644 --- a/packages/react-reconciler/src/ReactFiberCommitWork.js +++ b/packages/react-reconciler/src/ReactFiberCommitWork.js @@ -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; diff --git a/packages/react/src/__tests__/ReactProfiler-test.internal.js b/packages/react/src/__tests__/ReactProfiler-test.internal.js index e7e5396103972..c1a99452946f0 100644 --- a/packages/react/src/__tests__/ReactProfiler-test.internal.js +++ b/packages/react/src/__tests__/ReactProfiler-test.internal.js @@ -126,9 +126,7 @@ describe('Profiler', () => { if (__DEV__ && enableProfilerTimer) { it('should warn if required params are missing', () => { expect(() => { - expect(() => { - ReactTestRenderer.create(); - }).toThrow('onRender is not a function'); + ReactTestRenderer.create(); }).toWarnDev( 'Profiler must specify an "id" string and "onRender" function as props', {withoutStack: true},