Revert "Warn that ReactPerf does not work in the production build (#6884, #6975)"
This reverts commit f71dfbcbf020bea806827ef8b8e8a8743de8d615. Reverting because GitHub stripped the original PR author.
Dan Abramov committed
Jun 6, 2016 at 19:44 UTC
afe483790bda6d2df3b511eb81a0d58873905d29
3 files changed
+9
-104
src/renderers/shared/ReactDebugTool.js
+3
-1
@@ -208,7 +208,9 @@ var ReactDebugTool = {
208
}
209
},
210
getFlushHistory() {
211
- return flushHistory;
211
+ if (__DEV__) {
212
+ return flushHistory;
213
+ }
214
},
215
onBeginFlush() {
216
if (__DEV__) {
src/renderers/shared/ReactPerf.js
+6
-80
@@ -13,41 +13,17 @@
13
14
var ReactDebugTool = require('ReactDebugTool');
15
var warning = require('warning');
16
-var alreadyWarned = false;
16
17
function roundFloat(val, base = 2) {
18
var n = Math.pow(10, base);
19
return Math.floor(val * n) / n;
20
}
21
23
-function warnInProduction() {
24
- if (alreadyWarned) {
25
- return;
26
- }
27
- alreadyWarned = true;
28
- if (typeof console !== 'undefined') {
29
- console.error(
30
- 'ReactPerf is not supported in the production builds of React. ' +
31
- 'To collect measurements, please use the development build of React instead.'
32
- );
33
- }
34
-}
35
-
36
-function getLastMeasurements() {
37
- if (!__DEV__) {
38
- warnInProduction();
39
- return [];
40
- }
41
-
22
+function getFlushHistory() {
23
return ReactDebugTool.getFlushHistory();
24
}
25
45
-function getExclusive(flushHistory = getLastMeasurements()) {
46
- if (!__DEV__) {
47
- warnInProduction();
48
- return [];
49
- }
50
-
26
+function getExclusive(flushHistory = getFlushHistory()) {
27
var aggregatedStats = {};
28
var affectedIDs = {};
29
@@ -97,12 +73,7 @@ function getExclusive(flushHistory = getLastMeasurements()) {
73
);
74
}
75
100
-function getInclusive(flushHistory = getLastMeasurements()) {
101
- if (!__DEV__) {
102
- warnInProduction();
103
- return [];
104
- }
105
-
76
+function getInclusive(flushHistory = getFlushHistory()) {
77
var aggregatedStats = {};
78
var affectedIDs = {};
79
@@ -170,12 +141,7 @@ function getInclusive(flushHistory = getLastMeasurements()) {
141
);
142
}
143
173
-function getWasted(flushHistory = getLastMeasurements()) {
174
- if (!__DEV__) {
175
- warnInProduction();
176
- return [];
177
- }
178
-
144
+function getWasted(flushHistory = getFlushHistory()) {
145
var aggregatedStats = {};
146
var affectedIDs = {};
147
@@ -268,12 +234,7 @@ function getWasted(flushHistory = getLastMeasurements()) {
234
);
235
}
236
271
-function getOperations(flushHistory = getLastMeasurements()) {
272
- if (!__DEV__) {
273
- warnInProduction();
274
- return [];
275
- }
276
-
237
+function getOperations(flushHistory = getFlushHistory()) {
238
var stats = [];
239
flushHistory.forEach((flush, flushIndex) => {
240
var {operations, treeSnapshot} = flush;
@@ -297,11 +258,6 @@ function getOperations(flushHistory = getLastMeasurements()) {
258
}
259
260
function printExclusive(flushHistory) {
300
- if (!__DEV__) {
301
- warnInProduction();
302
- return;
303
- }
304
-
261
var stats = getExclusive(flushHistory);
262
var table = stats.map(item => {
263
var {key, instanceCount, totalDuration} = item;
@@ -323,11 +279,6 @@ function printExclusive(flushHistory) {
279
}
280
281
function printInclusive(flushHistory) {
326
- if (!__DEV__) {
327
- warnInProduction();
328
- return;
329
- }
330
-
282
var stats = getInclusive(flushHistory);
283
var table = stats.map(item => {
284
var {key, instanceCount, inclusiveRenderDuration, renderCount} = item;
@@ -342,11 +293,6 @@ function printInclusive(flushHistory) {
293
}
294
295
function printWasted(flushHistory) {
345
- if (!__DEV__) {
346
- warnInProduction();
347
- return;
348
- }
349
-
296
var stats = getWasted(flushHistory);
297
var table = stats.map(item => {
298
var {key, instanceCount, inclusiveRenderDuration, renderCount} = item;
@@ -361,11 +307,6 @@ function printWasted(flushHistory) {
307
}
308
309
function printOperations(flushHistory) {
364
- if (!__DEV__) {
365
- warnInProduction();
366
- return;
367
- }
368
-
310
var stats = getOperations(flushHistory);
311
var table = stats.map(stat => ({
312
'Owner > Node': stat.key,
@@ -403,34 +344,19 @@ function getMeasurementsSummaryMap(measurements) {
344
}
345
346
function start() {
406
- if (!__DEV__) {
407
- warnInProduction();
408
- return;
409
- }
410
-
347
ReactDebugTool.beginProfiling();
348
}
349
350
function stop() {
415
- if (!__DEV__) {
416
- warnInProduction();
417
- return;
418
- }
419
-
351
ReactDebugTool.endProfiling();
352
}
353
354
function isRunning() {
424
- if (!__DEV__) {
425
- warnInProduction();
426
- return false;
427
- }
428
-
355
return ReactDebugTool.isProfiling();
356
}
357
358
var ReactPerfAnalysis = {
433
- getLastMeasurements,
359
+ getLastMeasurements: getFlushHistory,
360
getExclusive,
361
getInclusive,
362
getWasted,
src/renderers/shared/__tests__/ReactPerf-test.js
-23
@@ -445,27 +445,4 @@ describe('ReactPerf', function() {
445
ReactPerf.stop();
446
expect(ReactPerf.isRunning()).toBe(false);
447
});
448
-
449
- it('should print console error only once', () => {
450
- __DEV__ = false;
451
-
452
- spyOn(console, 'error');
453
-
454
- expect(ReactPerf.getLastMeasurements()).toEqual([]);
455
- expect(ReactPerf.getExclusive()).toEqual([]);
456
- expect(ReactPerf.getInclusive()).toEqual([]);
457
- expect(ReactPerf.getWasted()).toEqual([]);
458
- expect(ReactPerf.getOperations()).toEqual([]);
459
- expect(ReactPerf.printExclusive()).toEqual(undefined);
460
- expect(ReactPerf.printInclusive()).toEqual(undefined);
461
- expect(ReactPerf.printWasted()).toEqual(undefined);
462
- expect(ReactPerf.printOperations()).toEqual(undefined);
463
- expect(ReactPerf.start()).toBe(undefined);
464
- expect(ReactPerf.stop()).toBe(undefined);
465
- expect(ReactPerf.isRunning()).toBe(false);
466
-
467
- expect(console.error.calls.count()).toBe(1);
468
-
469
- __DEV__ = true;
470
- })
448
});