-
Notifications
You must be signed in to change notification settings - Fork 46.2k
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
#6871 - Add not dev warning for ReactPerf & remove dev checking for ReactDebugTool method #6884
Changes from 1 commit
64412a0
878a99f
2840d5e
33ae3f6
25b0810
ec4f40c
d868334
a8b46fb
499d822
497d94b
2116205
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,23 +20,27 @@ function roundFloat(val, base = 2) { | |
return Math.floor(val * n) / n; | ||
} | ||
|
||
function returnWarnIfDevFalse(returningValue = 0) { | ||
if (!alreadyWarned) { | ||
alreadyWarned = true; | ||
warning(__DEV__, | ||
'ReactPerf is not supported in the production builds of React.' + | ||
'To collect measurements, please use the development build of React instead.'); | ||
} | ||
return returningValue; | ||
function warnInProduction() { | ||
if (typeof console !== 'undefined') { | ||
console.error('ReactPerf is not supported in the production builds of React.' + | ||
'To collect measurements, please use the development build of React instead.'); | ||
} | ||
} | ||
|
||
function getFlushHistory() { | ||
returnWarnIfDevFalse([]); | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return []; | ||
} | ||
|
||
return ReactDebugTool.getFlushHistory(); | ||
} | ||
|
||
function getExclusive(flushHistory = getFlushHistory()) { | ||
returnWarnIfDevFalse([]); | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return []; | ||
} | ||
|
||
var aggregatedStats = {}; | ||
var affectedIDs = {}; | ||
|
@@ -88,7 +92,10 @@ function getExclusive(flushHistory = getFlushHistory()) { | |
} | ||
|
||
function getInclusive(flushHistory = getFlushHistory()) { | ||
returnWarnIfDevFalse([]); | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return []; | ||
} | ||
|
||
var aggregatedStats = {}; | ||
var affectedIDs = {}; | ||
|
@@ -158,7 +165,10 @@ function getInclusive(flushHistory = getFlushHistory()) { | |
} | ||
|
||
function getWasted(flushHistory = getFlushHistory()) { | ||
returnWarnIfDevFalse([]); | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return []; | ||
} | ||
|
||
var aggregatedStats = {}; | ||
var affectedIDs = {}; | ||
|
@@ -253,7 +263,10 @@ function getWasted(flushHistory = getFlushHistory()) { | |
} | ||
|
||
function getOperations(flushHistory = getFlushHistory()) { | ||
returnWarnIfDevFalse([]); | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return []; | ||
} | ||
|
||
var stats = []; | ||
flushHistory.forEach((flush, flushIndex) => { | ||
|
@@ -278,7 +291,10 @@ function getOperations(flushHistory = getFlushHistory()) { | |
} | ||
|
||
function printExclusive(flushHistory) { | ||
returnWarnIfDevFalse(''); | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return ''; | ||
} | ||
|
||
var stats = getExclusive(flushHistory); | ||
var table = stats.map(item => { | ||
|
@@ -317,7 +333,10 @@ function printInclusive(flushHistory) { | |
} | ||
|
||
function printWasted(flushHistory) { | ||
returnWarnIfDevFalse(''); | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return ''; | ||
} | ||
|
||
var stats = getWasted(flushHistory); | ||
var table = stats.map(item => { | ||
|
@@ -333,7 +352,10 @@ function printWasted(flushHistory) { | |
} | ||
|
||
function printOperations(flushHistory) { | ||
returnWarnIfDevFalse(''); | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return ''; | ||
} | ||
|
||
var stats = getOperations(flushHistory); | ||
var table = stats.map(stat => ({ | ||
|
@@ -372,18 +394,28 @@ function getMeasurementsSummaryMap(measurements) { | |
} | ||
|
||
function start() { | ||
returnWarnIfDevFalse(); | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return; | ||
} | ||
ReactDebugTool.beginProfiling(); | ||
} | ||
|
||
function stop() { | ||
returnWarnIfDevFalse(); | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return; | ||
} | ||
|
||
alreadyWarned = false; | ||
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. This line looks like shouldn’t be here. 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. Oh, I see your point now. I propose we always warn just once. You can potentially leave 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. Fix other things but need some clarification here, you mean I should leave if (!__DEV__) {
warnInProduction();
return [];
} only in 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. No, I mean we call it everywhere because we don’t know which method gets called first, but I want the warning to only appear once, so let’s not reset the boolean variable ever. 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. Ooops, understood. |
||
ReactDebugTool.endProfiling(); | ||
} | ||
|
||
function isRunning() { | ||
returnWarnIfDevFalse(); | ||
if (!__DEV__) { | ||
warnInProduction(); | ||
return; | ||
} | ||
return ReactDebugTool.isProfiling(); | ||
} | ||
|
||
|
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.
No need to return an empty string—we can just
return;
here.