Skip to content

Commit 8b1b072

Browse files
authored
Wrap warning() calls in a DEV check for RN_* builds too (#10428)
* Wrap warning() calls in a DEV check for RN_* builds too. * Wrapped several warning() imports and calls in if-DEV checks. * Removed a useless variable (allTypesByEventName) and loop from ReactNativeBridgeEventPlugin.
1 parent e97143c commit 8b1b072

File tree

13 files changed

+70
-49
lines changed

13 files changed

+70
-49
lines changed

scripts/rollup/build.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ function updateBabelConfig(babelOpts, bundleType) {
124124
switch (bundleType) {
125125
case FB_DEV:
126126
case FB_PROD:
127+
case RN_DEV:
128+
case RN_PROD:
127129
return Object.assign({}, babelOpts, {
128130
plugins: babelOpts.plugins.concat([
129131
// Wrap warning() calls in a __DEV__ check so they are stripped from production.

src/isomorphic/classic/element/ReactElementValidator.js

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,14 +144,16 @@ function validateExplicitKey(element, parentType) {
144144
}
145145

146146
currentlyValidatingElement = element;
147-
warning(
148-
false,
149-
'Each child in an array or iterator should have a unique "key" prop.' +
150-
'%s%s See https://fb.me/react-warning-keys for more information.%s',
151-
currentComponentErrorInfo,
152-
childOwner,
153-
getStackAddendum(),
154-
);
147+
if (__DEV__) {
148+
warning(
149+
false,
150+
'Each child in an array or iterator should have a unique "key" prop.' +
151+
'%s%s See https://fb.me/react-warning-keys for more information.%s',
152+
currentComponentErrorInfo,
153+
childOwner,
154+
getStackAddendum(),
155+
);
156+
}
155157
currentlyValidatingElement = null;
156158
}
157159

src/renderers/dom/stack/client/ReactDOMComponent.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,12 @@ var memoizeStringOnly = require('fbjs/lib/memoizeStringOnly');
4242
var omittedCloseTags = require('omittedCloseTags');
4343
var validateDOMNesting = require('validateDOMNesting');
4444
var voidElementTags = require('voidElementTags');
45-
var warning = require('fbjs/lib/warning');
4645
var warnValidStyle = require('warnValidStyle');
4746

47+
if (__DEV__) {
48+
var warning = require('fbjs/lib/warning');
49+
}
50+
4851
var didWarnShadyDOM = false;
4952

5053
var Flags = ReactDOMComponentFlags;

src/renderers/native/ReactNativeBridgeEventPlugin.js

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,19 @@ var EventPropagators = require('EventPropagators');
1515
var SyntheticEvent = require('SyntheticEvent');
1616
var UIManager = require('UIManager');
1717

18-
var warning = require('fbjs/lib/warning');
19-
2018
var customBubblingEventTypes = UIManager.customBubblingEventTypes;
2119
var customDirectEventTypes = UIManager.customDirectEventTypes;
2220

23-
var allTypesByEventName = {};
24-
25-
for (var bubblingTypeName in customBubblingEventTypes) {
26-
allTypesByEventName[bubblingTypeName] =
27-
customBubblingEventTypes[bubblingTypeName];
28-
}
21+
if (__DEV__) {
22+
var warning = require('fbjs/lib/warning');
2923

30-
for (var directTypeName in customDirectEventTypes) {
31-
warning(
32-
!customBubblingEventTypes[directTypeName],
33-
'Event cannot be both direct and bubbling: %s',
34-
directTypeName,
35-
);
36-
allTypesByEventName[directTypeName] = customDirectEventTypes[directTypeName];
24+
for (var directTypeName in customDirectEventTypes) {
25+
warning(
26+
!customBubblingEventTypes[directTypeName],
27+
'Event cannot be both direct and bubbling: %s',
28+
directTypeName,
29+
);
30+
}
3731
}
3832

3933
var ReactNativeBridgeEventPlugin = {

src/renderers/native/ReactNativeEventEmitter.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ var ReactNativeComponentTree = require('ReactNativeComponentTree');
1818
var ReactNativeTagHandles = require('ReactNativeTagHandles');
1919
var ReactGenericBatching = require('ReactGenericBatching');
2020

21-
var warning = require('fbjs/lib/warning');
21+
if (__DEV__) {
22+
var warning = require('fbjs/lib/warning');
23+
}
2224

2325
/**
2426
* Version of `ReactBrowserEventEmitter` that works on the receiving side of a

src/renderers/native/findNodeHandle.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ var ReactNativeFiberRenderer = require('ReactNativeFiberRenderer');
1818
var {ReactCurrentOwner} = require('ReactGlobalSharedState');
1919

2020
var invariant = require('fbjs/lib/invariant');
21-
var warning = require('fbjs/lib/warning');
21+
22+
if (__DEV__) {
23+
var warning = require('fbjs/lib/warning');
24+
}
2225

2326
import type {Fiber} from 'ReactFiber';
2427
import type {ReactInstance} from 'ReactInstanceType';

src/renderers/shared/shared/event/eventPlugins/ResponderTouchHistoryStore.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,15 @@ function resetTouchRecord(touchRecord: TouchRecord, touch: Touch): void {
104104

105105
function getTouchIdentifier({identifier}: Touch): number {
106106
invariant(identifier != null, 'Touch object is missing identifier.');
107-
warning(
108-
identifier <= MAX_TOUCH_BANK,
109-
'Touch identifier %s is greater than maximum supported %s which causes ' +
110-
'performance issues backfilling array locations for all of the indices.',
111-
identifier,
112-
MAX_TOUCH_BANK,
113-
);
107+
if (__DEV__) {
108+
warning(
109+
identifier <= MAX_TOUCH_BANK,
110+
'Touch identifier %s is greater than maximum supported %s which causes ' +
111+
'performance issues backfilling array locations for all of the indices.',
112+
identifier,
113+
MAX_TOUCH_BANK,
114+
);
115+
}
114116
return identifier;
115117
}
116118

src/renderers/shared/stack/reconciler/ReactChildReconciler.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ var ReactReconciler = require('ReactReconciler');
1717
var instantiateReactComponent = require('instantiateReactComponent');
1818
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
1919
var traverseStackChildren = require('traverseStackChildren');
20-
var warning = require('fbjs/lib/warning');
20+
21+
if (__DEV__) {
22+
var warning = require('fbjs/lib/warning');
23+
}
2124

2225
var ReactComponentTreeHook;
2326

src/renderers/shared/stack/reconciler/ReactCompositeComponent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ var {ReactCurrentOwner} = require('ReactGlobalSharedState');
2424
if (__DEV__) {
2525
var {ReactDebugCurrentFrame} = require('ReactGlobalSharedState');
2626
var ReactDebugCurrentStack = require('ReactDebugCurrentStack');
27+
var warning = require('fbjs/lib/warning');
2728
var warningAboutMissingGetChildContext = {};
2829
}
2930

@@ -32,7 +33,6 @@ var emptyObject = require('fbjs/lib/emptyObject');
3233
var invariant = require('fbjs/lib/invariant');
3334
var shallowEqual = require('fbjs/lib/shallowEqual');
3435
var shouldUpdateReactComponent = require('shouldUpdateReactComponent');
35-
var warning = require('fbjs/lib/warning');
3636

3737
function StatelessComponent(Component) {}
3838
StatelessComponent.prototype.render = function() {

src/renderers/shared/stack/reconciler/ReactReconciler.js

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@
1414
var ReactRef = require('ReactRef');
1515
var ReactInstrumentation = require('ReactInstrumentation');
1616

17-
var warning = require('fbjs/lib/warning');
17+
if (__DEV__) {
18+
var warning = require('fbjs/lib/warning');
19+
}
1820

1921
/**
2022
* Helper to call ReactRef.attachRefs with this composite component, split out
@@ -187,16 +189,18 @@ var ReactReconciler = {
187189
updateBatchNumber,
188190
) {
189191
if (internalInstance._updateBatchNumber !== updateBatchNumber) {
190-
// The component's enqueued batch number should always be the current
191-
// batch or the following one.
192-
warning(
193-
internalInstance._updateBatchNumber == null ||
194-
internalInstance._updateBatchNumber === updateBatchNumber + 1,
195-
'performUpdateIfNecessary: Unexpected batch number (current %s, ' +
196-
'pending %s)',
197-
updateBatchNumber,
198-
internalInstance._updateBatchNumber,
199-
);
192+
if (__DEV__) {
193+
// The component's enqueued batch number should always be the current
194+
// batch or the following one.
195+
warning(
196+
internalInstance._updateBatchNumber == null ||
197+
internalInstance._updateBatchNumber === updateBatchNumber + 1,
198+
'performUpdateIfNecessary: Unexpected batch number (current %s, ' +
199+
'pending %s)',
200+
updateBatchNumber,
201+
internalInstance._updateBatchNumber,
202+
);
203+
}
200204
return;
201205
}
202206
if (__DEV__) {

0 commit comments

Comments
 (0)