-
Notifications
You must be signed in to change notification settings - Fork 47.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
prevent spamming warnings related to performance measurement code #7299
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -52,6 +52,9 @@ var currentTimerStartTime = null; | |
var currentTimerNestedFlushDuration = null; | ||
var currentTimerType = null; | ||
|
||
var beginLifeCycleTimerHasWarned = false; | ||
var endLifeCycleTimerHasWarned = false; | ||
|
||
function clearHistory() { | ||
ReactComponentTreeDevtool.purgeUnmountedComponents(); | ||
ReactHostOperationHistoryDevtool.clearHistory(); | ||
|
@@ -109,15 +112,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 (!beginLifeCycleTimerHasWarned) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can move this inside: warning(
!currentTimerType || beginLifeCycleTimerHasWarned,
...
) It only warns when the passed condition is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great, didn't know how |
||
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' | ||
); | ||
beginLifeCycleTimerHasWarned = true; | ||
} | ||
currentTimerStartTime = performanceNow(); | ||
currentTimerNestedFlushDuration = 0; | ||
currentTimerDebugID = debugID; | ||
|
@@ -128,15 +134,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 (!endLifeCycleTimerHasWarned) { | ||
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' | ||
); | ||
endLifeCycleTimerHasWarned = true; | ||
} | ||
if (isProfiling) { | ||
currentFlushMeasurements.push({ | ||
timerType, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it’s fine to have a single variable for this. If it warns once, something’s messed up already so it might warn more times.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just wanted to be safe about it. Thought maybe tests can produce situations that both functions generate warnings and then check the output of both. Changed it as you suggested in new commit.