From 1cc9a5dc718b7af8801a8ea00b00cf5043bc84d7 Mon Sep 17 00:00:00 2001 From: Sassan Haradji Date: Tue, 19 Jul 2016 15:16:12 +0430 Subject: [PATCH] prevent spamming warnings related to performance measurement code (#7299) * prevent spamming warnings related to performance measurement code * minor changes in names and such * - * - --- src/renderers/shared/ReactDebugTool.js | 44 +++++++++++++++----------- 1 file changed, 26 insertions(+), 18 deletions(-) diff --git a/src/renderers/shared/ReactDebugTool.js b/src/renderers/shared/ReactDebugTool.js index 006f538f54bc8..e8c5d2f16d659 100644 --- a/src/renderers/shared/ReactDebugTool.js +++ b/src/renderers/shared/ReactDebugTool.js @@ -52,6 +52,8 @@ var currentTimerStartTime = null; var currentTimerNestedFlushDuration = null; var currentTimerType = null; +var lifeCycleTimerHasWarned = false; + function clearHistory() { ReactComponentTreeDevtool.purgeUnmountedComponents(); ReactHostOperationHistoryDevtool.clearHistory(); @@ -109,15 +111,18 @@ function beginLifeCycleTimer(debugID, timerType) { if (currentFlushNesting === 0) { return; } - warning( - !currentTimerType, - 'There is an internal error in the React performance measurement code. ' + - 'Did not expect %s timer to start while %s timer is still in ' + - 'progress for %s instance.', - timerType, - currentTimerType || 'no', - (debugID === currentTimerDebugID) ? 'the same' : 'another' - ); + if (currentTimerType && !lifeCycleTimerHasWarned) { + warning( + false, + 'There is an internal error in the React performance measurement code. ' + + 'Did not expect %s timer to start while %s timer is still in ' + + 'progress for %s instance.', + timerType, + currentTimerType || 'no', + (debugID === currentTimerDebugID) ? 'the same' : 'another' + ); + lifeCycleTimerHasWarned = true; + } currentTimerStartTime = performanceNow(); currentTimerNestedFlushDuration = 0; currentTimerDebugID = debugID; @@ -128,15 +133,18 @@ function endLifeCycleTimer(debugID, timerType) { if (currentFlushNesting === 0) { return; } - warning( - currentTimerType === timerType, - 'There is an internal error in the React performance measurement code. ' + - 'We did not expect %s timer to stop while %s timer is still in ' + - 'progress for %s instance. Please report this as a bug in React.', - timerType, - currentTimerType || 'no', - (debugID === currentTimerDebugID) ? 'the same' : 'another' - ); + if (currentTimerType !== timerType && !lifeCycleTimerHasWarned) { + warning( + false, + 'There is an internal error in the React performance measurement code. ' + + 'We did not expect %s timer to stop while %s timer is still in ' + + 'progress for %s instance. Please report this as a bug in React.', + timerType, + currentTimerType || 'no', + (debugID === currentTimerDebugID) ? 'the same' : 'another' + ); + lifeCycleTimerHasWarned = true; + } if (isProfiling) { currentFlushMeasurements.push({ timerType,