@samitouri / QOS-React-2 / commits / 9ae5e38f18

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

Brian Vaughn committed Jul 24, 2019 at 14:20 UTC 9ae5e38f18b6e27dcddc7ecdfc38eefd678c095a
2 files changed +22 -22
packages/react-reconciler/src/ReactFiberCommitWork.js
+21 -19
@@ -567,25 +567,27 @@ function commitLifeCycles(
567 if (enableProfilerTimer) {
568 const onRender = finishedWork.memoizedProps.onRender;
569
570 - if (enableSchedulerTracing) {
571 - onRender(
572 - finishedWork.memoizedProps.id,
573 - current === null ? 'mount' : 'update',
574 - finishedWork.actualDuration,
575 - finishedWork.treeBaseDuration,
576 - finishedWork.actualStartTime,
577 - getCommitTime(),
578 - finishedRoot.memoizedInteractions,
579 - );
580 - } else {
581 - onRender(
582 - finishedWork.memoizedProps.id,
583 - current === null ? 'mount' : 'update',
584 - finishedWork.actualDuration,
585 - finishedWork.treeBaseDuration,
586 - finishedWork.actualStartTime,
587 - getCommitTime(),
588 - );
570 + if (typeof onRender === 'function') {
571 + if (enableSchedulerTracing) {
572 + onRender(
573 + finishedWork.memoizedProps.id,
574 + current === null ? 'mount' : 'update',
575 + finishedWork.actualDuration,
576 + finishedWork.treeBaseDuration,
577 + finishedWork.actualStartTime,
578 + getCommitTime(),
579 + finishedRoot.memoizedInteractions,
580 + );
581 + } else {
582 + onRender(
583 + finishedWork.memoizedProps.id,
584 + current === null ? 'mount' : 'update',
585 + finishedWork.actualDuration,
586 + finishedWork.treeBaseDuration,
587 + finishedWork.actualStartTime,
588 + getCommitTime(),
589 + );
590 + }
591 }
592 }
593 return;
packages/react/src/__tests__/ReactProfiler-test.internal.js
+1 -3
@@ -126,9 +126,7 @@ describe('Profiler', () => {
126 if (__DEV__ && enableProfilerTimer) {
127 it('should warn if required params are missing', () => {
128 expect(() => {
129 - expect(() => {
130 - ReactTestRenderer.create(<React.Profiler />);
131 - }).toThrow('onRender is not a function');
129 + ReactTestRenderer.create(<React.Profiler />);
130 }).toWarnDev(
131 'Profiler must specify an "id" string and "onRender" function as props',
132 {withoutStack: true},