-
Notifications
You must be signed in to change notification settings - Fork 47.3k
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
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,17 +13,31 @@ | |
|
||
var ReactDebugTool = require('ReactDebugTool'); | ||
var warning = require('warning'); | ||
var alreadyWarned = false; | ||
|
||
function roundFloat(val, base = 2) { | ||
var n = Math.pow(10, base); | ||
return Math.floor(val * n) / n; | ||
} | ||
|
||
function returnWarnIfDevFalse(returningValue = 0) { | ||
if (!alreadyWarned) { | ||
alreadyWarned = true; | ||
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. We should set this flag outside this if. Otherwise we check console every time. 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. Fixed |
||
warning(__DEV__, | ||
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. So, it turns out we can’t use 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.'); | ||
} | ||
return returningValue; | ||
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. Let’s just make it return nothing, and explicitly return in the methods. |
||
} | ||
|
||
function getFlushHistory() { | ||
returnWarnIfDevFalse([]); | ||
return ReactDebugTool.getFlushHistory(); | ||
} | ||
|
||
function getExclusive(flushHistory = getFlushHistory()) { | ||
returnWarnIfDevFalse([]); | ||
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. Let’s replace these with explicit blocks: if (!__DEV__) {
warnInProduction();
return [];
} |
||
|
||
var aggregatedStats = {}; | ||
var affectedIDs = {}; | ||
|
||
|
@@ -74,6 +88,8 @@ function getExclusive(flushHistory = getFlushHistory()) { | |
} | ||
|
||
function getInclusive(flushHistory = getFlushHistory()) { | ||
returnWarnIfDevFalse([]); | ||
|
||
var aggregatedStats = {}; | ||
var affectedIDs = {}; | ||
|
||
|
@@ -142,6 +158,8 @@ function getInclusive(flushHistory = getFlushHistory()) { | |
} | ||
|
||
function getWasted(flushHistory = getFlushHistory()) { | ||
returnWarnIfDevFalse([]); | ||
|
||
var aggregatedStats = {}; | ||
var affectedIDs = {}; | ||
|
||
|
@@ -235,6 +253,8 @@ function getWasted(flushHistory = getFlushHistory()) { | |
} | ||
|
||
function getOperations(flushHistory = getFlushHistory()) { | ||
returnWarnIfDevFalse([]); | ||
|
||
var stats = []; | ||
flushHistory.forEach((flush, flushIndex) => { | ||
var {operations, treeSnapshot} = flush; | ||
|
@@ -258,6 +278,8 @@ function getOperations(flushHistory = getFlushHistory()) { | |
} | ||
|
||
function printExclusive(flushHistory) { | ||
returnWarnIfDevFalse(''); | ||
|
||
var stats = getExclusive(flushHistory); | ||
var table = stats.map(item => { | ||
var {key, instanceCount, totalDuration} = item; | ||
|
@@ -279,6 +301,8 @@ function printExclusive(flushHistory) { | |
} | ||
|
||
function printInclusive(flushHistory) { | ||
returnWarnIfDevFalse(''); | ||
|
||
var stats = getInclusive(flushHistory); | ||
var table = stats.map(item => { | ||
var {key, instanceCount, inclusiveRenderDuration, renderCount} = item; | ||
|
@@ -293,6 +317,8 @@ function printInclusive(flushHistory) { | |
} | ||
|
||
function printWasted(flushHistory) { | ||
returnWarnIfDevFalse(''); | ||
|
||
var stats = getWasted(flushHistory); | ||
var table = stats.map(item => { | ||
var {key, instanceCount, inclusiveRenderDuration, renderCount} = item; | ||
|
@@ -307,6 +333,8 @@ function printWasted(flushHistory) { | |
} | ||
|
||
function printOperations(flushHistory) { | ||
returnWarnIfDevFalse(''); | ||
|
||
var stats = getOperations(flushHistory); | ||
var table = stats.map(stat => ({ | ||
'Owner > Node': stat.key, | ||
|
@@ -344,14 +372,18 @@ function getMeasurementsSummaryMap(measurements) { | |
} | ||
|
||
function start() { | ||
returnWarnIfDevFalse(); | ||
ReactDebugTool.beginProfiling(); | ||
} | ||
|
||
function stop() { | ||
returnWarnIfDevFalse(); | ||
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(); | ||
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.
Let’s call it
warnInProduction
.