Disable DebugTools in production (#7189)
Dan Abramov committed
Jul 5, 2016 at 19:41 UTC
5d31ebcf5fc33732d0a9c8c7ff139f52a989fbd6
4 files changed
+97
-109
src/renderers/dom/shared/ReactDOMDebugTool.js
+18
-22
@@ -11,6 +11,8 @@
11
12
'use strict';
13
14
+var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool');
15
+var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool');
16
var ReactDebugTool = require('ReactDebugTool');
17
18
var warning = require('warning');
@@ -19,23 +21,21 @@ var eventHandlers = [];
21
var handlerDoesThrowForEvent = {};
22
23
function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) {
22
- if (__DEV__) {
23
- eventHandlers.forEach(function(handler) {
24
- try {
25
- if (handler[handlerFunctionName]) {
26
- handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5);
27
- }
28
- } catch (e) {
29
- warning(
30
- handlerDoesThrowForEvent[handlerFunctionName],
31
- 'exception thrown by devtool while handling %s: %s',
32
- handlerFunctionName,
33
- e + '\n' + e.stack
34
- );
35
- handlerDoesThrowForEvent[handlerFunctionName] = true;
24
+ eventHandlers.forEach(function(handler) {
25
+ try {
26
+ if (handler[handlerFunctionName]) {
27
+ handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5);
28
}
37
- });
38
- }
29
+ } catch (e) {
30
+ warning(
31
+ handlerDoesThrowForEvent[handlerFunctionName],
32
+ 'exception thrown by devtool while handling %s: %s',
33
+ handlerFunctionName,
34
+ e + '\n' + e.stack
35
+ );
36
+ handlerDoesThrowForEvent[handlerFunctionName] = true;
37
+ }
38
+ });
39
}
40
41
var ReactDOMDebugTool = {
@@ -66,11 +66,7 @@ var ReactDOMDebugTool = {
66
},
67
};
68
69
-if (__DEV__) {
70
- var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool');
71
- var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool');
72
- ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyDevtool);
73
- ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropDevtool);
74
-}
69
+ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyDevtool);
70
+ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropDevtool);
71
72
module.exports = ReactDOMDebugTool;
src/renderers/dom/shared/ReactDOMInstrumentation.js
+7
-2
@@ -11,6 +11,11 @@
11
12
'use strict';
13
14
-var ReactDOMDebugTool = require('ReactDOMDebugTool');
14
+var debugTool = null;
15
16
-module.exports = {debugTool: ReactDOMDebugTool};
16
+if (__DEV__) {
17
+ var ReactDOMDebugTool = require('ReactDOMDebugTool');
18
+ debugTool = ReactDOMDebugTool;
19
+}
20
+
21
+module.exports = {debugTool};
src/renderers/shared/ReactDebugTool.js
+65
-83
@@ -11,6 +11,10 @@
11
12
'use strict';
13
14
+var ReactInvalidSetStateWarningDevTool = require('ReactInvalidSetStateWarningDevTool');
15
+var ReactHostOperationHistoryDevtool = require('ReactHostOperationHistoryDevtool');
16
+var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
17
+var ReactChildrenMutationWarningDevtool = require('ReactChildrenMutationWarningDevtool');
18
var ExecutionEnvironment = require('ExecutionEnvironment');
19
20
var performanceNow = require('performanceNow');
@@ -20,23 +24,21 @@ var eventHandlers = [];
24
var handlerDoesThrowForEvent = {};
25
26
function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) {
23
- if (__DEV__) {
24
- eventHandlers.forEach(function(handler) {
25
- try {
26
- if (handler[handlerFunctionName]) {
27
- handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5);
28
- }
29
- } catch (e) {
30
- warning(
31
- handlerDoesThrowForEvent[handlerFunctionName],
32
- 'exception thrown by devtool while handling %s: %s',
33
- handlerFunctionName,
34
- e + '\n' + e.stack
35
- );
36
- handlerDoesThrowForEvent[handlerFunctionName] = true;
27
+ eventHandlers.forEach(function(handler) {
28
+ try {
29
+ if (handler[handlerFunctionName]) {
30
+ handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5);
31
}
38
- });
39
- }
32
+ } catch (e) {
33
+ warning(
34
+ handlerDoesThrowForEvent[handlerFunctionName],
35
+ 'exception thrown by devtool while handling %s: %s',
36
+ handlerFunctionName,
37
+ e + '\n' + e.stack
38
+ );
39
+ handlerDoesThrowForEvent[handlerFunctionName] = true;
40
+ }
41
+ });
42
}
43
44
var isProfiling = false;
@@ -73,32 +75,30 @@ function getTreeSnapshot(registeredIDs) {
75
}
76
77
function resetMeasurements() {
76
- if (__DEV__) {
77
- var previousStartTime = currentFlushStartTime;
78
- var previousMeasurements = currentFlushMeasurements || [];
79
- var previousOperations = ReactHostOperationHistoryDevtool.getHistory();
80
-
81
- if (!isProfiling || currentFlushNesting === 0) {
82
- currentFlushStartTime = null;
83
- currentFlushMeasurements = null;
84
- clearHistory();
85
- return;
86
- }
87
-
88
- if (previousMeasurements.length || previousOperations.length) {
89
- var registeredIDs = ReactComponentTreeDevtool.getRegisteredIDs();
90
- flushHistory.push({
91
- duration: performanceNow() - previousStartTime,
92
- measurements: previousMeasurements || [],
93
- operations: previousOperations || [],
94
- treeSnapshot: getTreeSnapshot(registeredIDs),
95
- });
96
- }
78
+ var previousStartTime = currentFlushStartTime;
79
+ var previousMeasurements = currentFlushMeasurements || [];
80
+ var previousOperations = ReactHostOperationHistoryDevtool.getHistory();
81
82
+ if (!isProfiling || currentFlushNesting === 0) {
83
+ currentFlushStartTime = null;
84
+ currentFlushMeasurements = null;
85
clearHistory();
99
- currentFlushStartTime = performanceNow();
100
- currentFlushMeasurements = [];
86
+ return;
87
+ }
88
+
89
+ if (previousMeasurements.length || previousOperations.length) {
90
+ var registeredIDs = ReactComponentTreeDevtool.getRegisteredIDs();
91
+ flushHistory.push({
92
+ duration: performanceNow() - previousStartTime,
93
+ measurements: previousMeasurements || [],
94
+ operations: previousOperations || [],
95
+ treeSnapshot: getTreeSnapshot(registeredIDs),
96
+ });
97
}
98
+
99
+ clearHistory();
100
+ currentFlushStartTime = performanceNow();
101
+ currentFlushMeasurements = [];
102
}
103
104
function checkDebugID(debugID) {
@@ -187,57 +187,45 @@ var ReactDebugTool = {
187
return isProfiling;
188
},
189
beginProfiling() {
190
- if (__DEV__) {
191
- if (isProfiling) {
192
- return;
193
- }
194
-
195
- isProfiling = true;
196
- flushHistory.length = 0;
197
- resetMeasurements();
190
+ if (isProfiling) {
191
+ return;
192
}
193
+
194
+ isProfiling = true;
195
+ flushHistory.length = 0;
196
+ resetMeasurements();
197
},
198
endProfiling() {
201
- if (__DEV__) {
202
- if (!isProfiling) {
203
- return;
204
- }
205
-
206
- isProfiling = false;
207
- resetMeasurements();
199
+ if (!isProfiling) {
200
+ return;
201
}
202
+
203
+ isProfiling = false;
204
+ resetMeasurements();
205
},
206
getFlushHistory() {
207
return flushHistory;
208
},
209
onBeginFlush() {
214
- if (__DEV__) {
215
- currentFlushNesting++;
216
- resetMeasurements();
217
- pauseCurrentLifeCycleTimer();
218
- }
210
+ currentFlushNesting++;
211
+ resetMeasurements();
212
+ pauseCurrentLifeCycleTimer();
213
emitEvent('onBeginFlush');
214
},
215
onEndFlush() {
222
- if (__DEV__) {
223
- resetMeasurements();
224
- currentFlushNesting--;
225
- resumeCurrentLifeCycleTimer();
226
- }
216
+ resetMeasurements();
217
+ currentFlushNesting--;
218
+ resumeCurrentLifeCycleTimer();
219
emitEvent('onEndFlush');
220
},
221
onBeginLifeCycleTimer(debugID, timerType) {
222
checkDebugID(debugID);
223
emitEvent('onBeginLifeCycleTimer', debugID, timerType);
232
- if (__DEV__) {
233
- beginLifeCycleTimer(debugID, timerType);
234
- }
224
+ beginLifeCycleTimer(debugID, timerType);
225
},
226
onEndLifeCycleTimer(debugID, timerType) {
227
checkDebugID(debugID);
238
- if (__DEV__) {
239
- endLifeCycleTimer(debugID, timerType);
240
- }
228
+ endLifeCycleTimer(debugID, timerType);
229
emitEvent('onEndLifeCycleTimer', debugID, timerType);
230
},
231
onBeginReconcilerTimer(debugID, timerType) {
@@ -318,19 +306,13 @@ var ReactDebugTool = {
306
},
307
};
308
321
-if (__DEV__) {
322
- var ReactInvalidSetStateWarningDevTool = require('ReactInvalidSetStateWarningDevTool');
323
- var ReactHostOperationHistoryDevtool = require('ReactHostOperationHistoryDevtool');
324
- var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
325
- var ReactChildrenMutationWarningDevtool = require('ReactChildrenMutationWarningDevtool');
326
- ReactDebugTool.addDevtool(ReactInvalidSetStateWarningDevTool);
327
- ReactDebugTool.addDevtool(ReactComponentTreeDevtool);
328
- ReactDebugTool.addDevtool(ReactHostOperationHistoryDevtool);
329
- ReactDebugTool.addDevtool(ReactChildrenMutationWarningDevtool);
330
- var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
331
- if ((/[?&]react_perf\b/).test(url)) {
332
- ReactDebugTool.beginProfiling();
333
- }
309
+ReactDebugTool.addDevtool(ReactInvalidSetStateWarningDevTool);
310
+ReactDebugTool.addDevtool(ReactComponentTreeDevtool);
311
+ReactDebugTool.addDevtool(ReactHostOperationHistoryDevtool);
312
+ReactDebugTool.addDevtool(ReactChildrenMutationWarningDevtool);
313
+var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
314
+if ((/[?&]react_perf\b/).test(url)) {
315
+ ReactDebugTool.beginProfiling();
316
}
317
318
module.exports = ReactDebugTool;
src/renderers/shared/ReactInstrumentation.js
+7
-2
@@ -11,6 +11,11 @@
11
12
'use strict';
13
14
-var ReactDebugTool = require('ReactDebugTool');
14
+var debugTool = null;
15
16
-module.exports = {debugTool: ReactDebugTool};
16
+if (__DEV__) {
17
+ var ReactDebugTool = require('ReactDebugTool');
18
+ debugTool = ReactDebugTool;
19
+}
20
+
21
+module.exports = {debugTool};