added guards in place to prevent mixed prod+dev errors from occuring
Dominic Gannaway committed
Mar 2, 2017 at 23:06 UTC
91de17ec5212c4fc16c01c66db3645f52901c1f9
5 files changed
+20
-25
src/isomorphic/classic/element/ReactDebugCurrentFrame.js
+2
-2
@@ -38,7 +38,7 @@ if (__DEV__) {
38
if (typeof current === 'number') {
39
// DebugID from Stack.
40
const debugID = current;
41
- stack = getStackAddendumByID(debugID);
41
+ stack = getStackAddendumByID && getStackAddendumByID(debugID);
42
} else if (typeof current.tag === 'number') {
43
// This is a Fiber.
44
// The stack will only be correct if this is a work in progress
@@ -47,7 +47,7 @@ if (__DEV__) {
47
stack = getStackAddendumByWorkInProgressFiber(workInProgress);
48
}
49
} else if (element !== null) {
50
- stack = getCurrentStackAddendum(element);
50
+ stack = getCurrentStackAddendum && getCurrentStackAddendum(element);
51
}
52
return stack;
53
};
src/renderers/shared/ReactDebugTool.js
+15
-11
@@ -120,7 +120,9 @@ if (__DEV__) {
120
var lifeCycleTimerHasWarned = false;
121
122
const clearHistory = function() {
123
- purgeUnmountedComponents();
123
+ if (purgeUnmountedComponents) {
124
+ purgeUnmountedComponents();
125
+ }
126
ReactHostOperationHistoryHook.clearHistory();
127
};
128
@@ -156,14 +158,16 @@ if (__DEV__) {
158
}
159
160
if (previousMeasurements.length || previousOperations.length) {
159
- var registeredIDs = getRegisteredIDs();
160
-
161
- flushHistory.push({
162
- duration: performanceNow() - previousStartTime,
163
- measurements: previousMeasurements || [],
164
- operations: previousOperations || [],
165
- treeSnapshot: getTreeSnapshot(registeredIDs),
166
- });
161
+ if (getRegisteredIDs) {
162
+ var registeredIDs = getRegisteredIDs();
163
+
164
+ flushHistory.push({
165
+ duration: performanceNow() - previousStartTime,
166
+ measurements: previousMeasurements || [],
167
+ operations: previousOperations || [],
168
+ treeSnapshot: getTreeSnapshot(registeredIDs),
169
+ });
170
+ }
171
}
172
173
clearHistory();
@@ -266,7 +270,7 @@ if (__DEV__) {
270
if (!isProfiling || !canUsePerformanceMeasure) {
271
return false;
272
}
269
- var element = getElement(debugID);
273
+ var element = getElement && getElement(debugID);
274
if (element == null || typeof element !== 'object') {
275
return false;
276
}
@@ -293,7 +297,7 @@ if (__DEV__) {
297
}
298
299
var markName = `${debugID}::${markType}`;
296
- var displayName = getDisplayName(debugID) || 'Unknown';
300
+ var displayName = getDisplayName && getDisplayName(debugID) || 'Unknown';
301
302
// Chrome has an issue of dropping markers recorded too fast:
303
// https://bugs.chromium.org/p/chromium/issues/detail?id=640652
src/renderers/shared/stack/reconciler/ReactRef.js
+1
-1
@@ -49,7 +49,7 @@ function attachRef(ref, component, owner) {
49
if (element && element._source) {
50
warningKey = element._source.fileName + ':' + element._source.lineNumber;
51
}
52
- if (!warnedAboutStatelessRefs[warningKey]) {
52
+ if (!warnedAboutStatelessRefs[warningKey] && getStackAddendumByID) {
53
warnedAboutStatelessRefs[warningKey] = true;
54
warning(
55
false,
src/shared/utils/flattenChildren.js
+1
-1
@@ -55,7 +55,7 @@ function flattenSingleChildIntoContext(
55
}
56
const { getStackAddendumByID }: ComponentTreeHookDevType = (ReactComponentTreeHook: any);
57
58
- if (!keyUnique) {
58
+ if (!keyUnique && getStackAddendumByID) {
59
warning(
60
false,
61
'flattenChildren(...): Encountered two children with the same key, ' +
src/umd/ReactUMDEntry.js
+1
-10
@@ -17,17 +17,8 @@ var React = require('React');
17
var ReactUMDEntry = Object.assign({
18
__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED: {
19
ReactCurrentOwner: require('react/lib/ReactCurrentOwner'),
20
+ ReactComponentTreeHook: require('react/lib/ReactComponentTreeHook'),
21
},
22
}, React);
23
23
-if (__DEV__) {
24
- Object.assign(
25
- ReactUMDEntry.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED,
26
- {
27
- // ReactComponentTreeHook should not be included in production.
28
- ReactComponentTreeHook: require('react/lib/ReactComponentTreeHook'),
29
- }
30
- );
31
-}
32
-
24
module.exports = ReactUMDEntry;