mirror of
https://github.com/facebook/react.git
synced 2025-11-01 09:12:30 +00:00
Disable DebugTools in production (#7189)
(cherry picked from commit 5d31ebcf5f)
This commit is contained in:
committed by
Paul O’Shannessy
parent
f6b619aab1
commit
25528eacbc
@@ -11,6 +11,8 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var ReactDOMNullInputValuePropDevtool = require('ReactDOMNullInputValuePropDevtool');
|
||||
var ReactDOMUnknownPropertyDevtool = require('ReactDOMUnknownPropertyDevtool');
|
||||
var ReactDebugTool = require('ReactDebugTool');
|
||||
|
||||
var warning = require('warning');
|
||||
@@ -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 = {
|
||||
@@ -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;
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -11,6 +11,9 @@
|
||||
|
||||
'use strict';
|
||||
|
||||
var ReactInvalidSetStateWarningDevTool = require('ReactInvalidSetStateWarningDevTool');
|
||||
var ReactHostOperationHistoryDevtool = require('ReactHostOperationHistoryDevtool');
|
||||
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
|
||||
var ExecutionEnvironment = require('ExecutionEnvironment');
|
||||
|
||||
var performanceNow = require('performanceNow');
|
||||
@@ -20,23 +23,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;
|
||||
@@ -73,32 +74,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) {
|
||||
@@ -187,57 +186,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) {
|
||||
@@ -310,17 +297,12 @@ var ReactDebugTool = {
|
||||
},
|
||||
};
|
||||
|
||||
if (__DEV__) {
|
||||
var ReactInvalidSetStateWarningDevTool = require('ReactInvalidSetStateWarningDevTool');
|
||||
var ReactHostOperationHistoryDevtool = require('ReactHostOperationHistoryDevtool');
|
||||
var ReactComponentTreeDevtool = require('ReactComponentTreeDevtool');
|
||||
ReactDebugTool.addDevtool(ReactInvalidSetStateWarningDevTool);
|
||||
ReactDebugTool.addDevtool(ReactComponentTreeDevtool);
|
||||
ReactDebugTool.addDevtool(ReactHostOperationHistoryDevtool);
|
||||
var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
|
||||
if ((/[?&]react_perf\b/).test(url)) {
|
||||
ReactDebugTool.beginProfiling();
|
||||
}
|
||||
ReactDebugTool.addDevtool(ReactInvalidSetStateWarningDevTool);
|
||||
ReactDebugTool.addDevtool(ReactComponentTreeDevtool);
|
||||
ReactDebugTool.addDevtool(ReactHostOperationHistoryDevtool);
|
||||
var url = (ExecutionEnvironment.canUseDOM && window.location.href) || '';
|
||||
if ((/[?&]react_perf\b/).test(url)) {
|
||||
ReactDebugTool.beginProfiling();
|
||||
}
|
||||
|
||||
module.exports = ReactDebugTool;
|
||||
|
||||
@@ -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};
|
||||
|
||||
Reference in New Issue
Block a user