Skip to content

Commit

Permalink
Disable DebugTools in production (facebook#7189)
Browse files Browse the repository at this point in the history
  • Loading branch information
gaearon authored and usmanajmal committed Jul 11, 2016
1 parent 4007174 commit 2549493
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 109 deletions.
40 changes: 18 additions & 22 deletions src/renderers/dom/shared/ReactDOMDebugTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

'use strict';

var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool');
var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool');
var ReactDebugTool = require('ReactDebugTool');

var warning = require('warning');
Expand All @@ -19,23 +21,21 @@ var eventHandlers = [];
var handlerDoesThrowForEvent = {};

function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) {
if (__DEV__) {
eventHandlers.forEach(function(handler) {
try {
if (handler[handlerFunctionName]) {
handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5);
}
} catch (e) {
warning(
handlerDoesThrowForEvent[handlerFunctionName],
'exception thrown by devtool while handling %s: %s',
handlerFunctionName,
e + '\n' + e.stack
);
handlerDoesThrowForEvent[handlerFunctionName] = true;
eventHandlers.forEach(function(handler) {
try {
if (handler[handlerFunctionName]) {
handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5);
}
});
}
} catch (e) {
warning(
handlerDoesThrowForEvent[handlerFunctionName],
'exception thrown by devtool while handling %s: %s',
handlerFunctionName,
e + '\n' + e.stack
);
handlerDoesThrowForEvent[handlerFunctionName] = true;
}
});
}

var ReactDOMDebugTool = {
Expand Down Expand Up @@ -66,11 +66,7 @@ var ReactDOMDebugTool = {
},
};

if (__DEV__) {
var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool');
var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool');
ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyDevtool);
ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropDevtool);
}
ReactDOMDebugTool.addDevtool(ReactDOMUnknownPropertyDevtool);
ReactDOMDebugTool.addDevtool(ReactDOMNullInputValuePropDevtool);

module.exports = ReactDOMDebugTool;
9 changes: 7 additions & 2 deletions src/renderers/dom/shared/ReactDOMInstrumentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

'use strict';

var ReactDOMDebugTool = require('ReactDOMDebugTool');
var debugTool = null;

module.exports = {debugTool: ReactDOMDebugTool};
if (__DEV__) {
var ReactDOMDebugTool = require('ReactDOMDebugTool');
debugTool = ReactDOMDebugTool;
}

module.exports = {debugTool};
148 changes: 65 additions & 83 deletions src/renderers/shared/ReactDebugTool.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@

'use strict';

var ReactInvalidSetStateWarningDevTool = require('ReactInvalidSetStateWarningDevTool');
var ReactHostOperationHistoryDevtool = require('ReactHostOperationHistoryDevtool');
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
var ReactChildrenMutationWarningDevtool = require('ReactChildrenMutationWarningDevtool');
var ExecutionEnvironment = require('ExecutionEnvironment');

var performanceNow = require('performanceNow');
Expand All @@ -20,23 +24,21 @@ var eventHandlers = [];
var handlerDoesThrowForEvent = {};

function emitEvent(handlerFunctionName, arg1, arg2, arg3, arg4, arg5) {
if (__DEV__) {
eventHandlers.forEach(function(handler) {
try {
if (handler[handlerFunctionName]) {
handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5);
}
} catch (e) {
warning(
handlerDoesThrowForEvent[handlerFunctionName],
'exception thrown by devtool while handling %s: %s',
handlerFunctionName,
e + '\n' + e.stack
);
handlerDoesThrowForEvent[handlerFunctionName] = true;
eventHandlers.forEach(function(handler) {
try {
if (handler[handlerFunctionName]) {
handler[handlerFunctionName](arg1, arg2, arg3, arg4, arg5);
}
});
}
} catch (e) {
warning(
handlerDoesThrowForEvent[handlerFunctionName],
'exception thrown by devtool while handling %s: %s',
handlerFunctionName,
e + '\n' + e.stack
);
handlerDoesThrowForEvent[handlerFunctionName] = true;
}
});
}

var isProfiling = false;
Expand Down Expand Up @@ -73,32 +75,30 @@ function getTreeSnapshot(registeredIDs) {
}

function resetMeasurements() {
if (__DEV__) {
var previousStartTime = currentFlushStartTime;
var previousMeasurements = currentFlushMeasurements || [];
var previousOperations = ReactHostOperationHistoryDevtool.getHistory();

if (!isProfiling || currentFlushNesting === 0) {
currentFlushStartTime = null;
currentFlushMeasurements = null;
clearHistory();
return;
}

if (previousMeasurements.length || previousOperations.length) {
var registeredIDs = ReactComponentTreeDevtool.getRegisteredIDs();
flushHistory.push({
duration: performanceNow() - previousStartTime,
measurements: previousMeasurements || [],
operations: previousOperations || [],
treeSnapshot: getTreeSnapshot(registeredIDs),
});
}
var previousStartTime = currentFlushStartTime;
var previousMeasurements = currentFlushMeasurements || [];
var previousOperations = ReactHostOperationHistoryDevtool.getHistory();

if (!isProfiling || currentFlushNesting === 0) {
currentFlushStartTime = null;
currentFlushMeasurements = null;
clearHistory();
currentFlushStartTime = performanceNow();
currentFlushMeasurements = [];
return;
}

if (previousMeasurements.length || previousOperations.length) {
var registeredIDs = ReactComponentTreeDevtool.getRegisteredIDs();
flushHistory.push({
duration: performanceNow() - previousStartTime,
measurements: previousMeasurements || [],
operations: previousOperations || [],
treeSnapshot: getTreeSnapshot(registeredIDs),
});
}

clearHistory();
currentFlushStartTime = performanceNow();
currentFlushMeasurements = [];
}

function checkDebugID(debugID) {
Expand Down Expand Up @@ -187,57 +187,45 @@ var ReactDebugTool = {
return isProfiling;
},
beginProfiling() {
if (__DEV__) {
if (isProfiling) {
return;
}

isProfiling = true;
flushHistory.length = 0;
resetMeasurements();
if (isProfiling) {
return;
}

isProfiling = true;
flushHistory.length = 0;
resetMeasurements();
},
endProfiling() {
if (__DEV__) {
if (!isProfiling) {
return;
}

isProfiling = false;
resetMeasurements();
if (!isProfiling) {
return;
}

isProfiling = false;
resetMeasurements();
},
getFlushHistory() {
return flushHistory;
},
onBeginFlush() {
if (__DEV__) {
currentFlushNesting++;
resetMeasurements();
pauseCurrentLifeCycleTimer();
}
currentFlushNesting++;
resetMeasurements();
pauseCurrentLifeCycleTimer();
emitEvent('onBeginFlush');
},
onEndFlush() {
if (__DEV__) {
resetMeasurements();
currentFlushNesting--;
resumeCurrentLifeCycleTimer();
}
resetMeasurements();
currentFlushNesting--;
resumeCurrentLifeCycleTimer();
emitEvent('onEndFlush');
},
onBeginLifeCycleTimer(debugID, timerType) {
checkDebugID(debugID);
emitEvent('onBeginLifeCycleTimer', debugID, timerType);
if (__DEV__) {
beginLifeCycleTimer(debugID, timerType);
}
beginLifeCycleTimer(debugID, timerType);
},
onEndLifeCycleTimer(debugID, timerType) {
checkDebugID(debugID);
if (__DEV__) {
endLifeCycleTimer(debugID, timerType);
}
endLifeCycleTimer(debugID, timerType);
emitEvent('onEndLifeCycleTimer', debugID, timerType);
},
onBeginReconcilerTimer(debugID, timerType) {
Expand Down Expand Up @@ -318,19 +306,13 @@ var ReactDebugTool = {
},
};

if (__DEV__) {
var ReactInvalidSetStateWarningDevTool = require('ReactInvalidSetStateWarningDevTool');
var ReactHostOperationHistoryDevtool = require('ReactHostOperationHistoryDevtool');
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
var ReactChildrenMutationWarningDevtool = require('ReactChildrenMutationWarningDevtool');
ReactDebugTool.addDevtool(ReactInvalidSetStateWarningDevTool);
ReactDebugTool.addDevtool(ReactComponentTreeDevtool);
ReactDebugTool.addDevtool(ReactHostOperationHistoryDevtool);
ReactDebugTool.addDevtool(ReactChildrenMutationWarningDevtool);
var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
if ((/[?&]react_perf\b/).test(url)) {
ReactDebugTool.beginProfiling();
}
ReactDebugTool.addDevtool(ReactInvalidSetStateWarningDevTool);
ReactDebugTool.addDevtool(ReactComponentTreeDevtool);
ReactDebugTool.addDevtool(ReactHostOperationHistoryDevtool);
ReactDebugTool.addDevtool(ReactChildrenMutationWarningDevtool);
var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
if ((/[?&]react_perf\b/).test(url)) {
ReactDebugTool.beginProfiling();
}

module.exports = ReactDebugTool;
9 changes: 7 additions & 2 deletions src/renderers/shared/ReactInstrumentation.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@

'use strict';

var ReactDebugTool = require('ReactDebugTool');
var debugTool = null;

module.exports = {debugTool: ReactDebugTool};
if (__DEV__) {
var ReactDebugTool = require('ReactDebugTool');
debugTool = ReactDebugTool;
}

module.exports = {debugTool};

0 comments on commit 2549493

Please sign in to comment.