Skip to content

Commit

Permalink
Add guard to ensure Profiler onRender prop is function before calling (
Browse files Browse the repository at this point in the history
  • Loading branch information
Brian Vaughn authored Jul 24, 2019
1 parent 144dba1 commit 9ae5e38
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 22 deletions.
40 changes: 21 additions & 19 deletions packages/react-reconciler/src/ReactFiberCommitWork.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions packages/react/src/__tests__/ReactProfiler-test.internal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 9ae5e38

Please sign in to comment.