Skip to content

Commit 130a164

Browse files
committed
Merge pull request facebook#3117 from jsfb/use-warning-module
Flip console.warn to use warning module.
2 parents f6f0bab + 4e55439 commit 130a164

File tree

9 files changed

+53
-59
lines changed

9 files changed

+53
-59
lines changed

src/addons/transitions/ReactCSSTransitionGroupChild.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var CSSCore = require('CSSCore');
1818
var ReactTransitionEvents = require('ReactTransitionEvents');
1919

2020
var onlyChild = require('onlyChild');
21+
var warning = require('warning');
2122

2223
// We don't remove the element from the DOM until we receive an animationend or
2324
// transitionend event. If the user screws up and forgets to add an animation
@@ -31,11 +32,13 @@ var noEventListener = null;
3132

3233
if (__DEV__) {
3334
noEventListener = function() {
34-
console.warn(
35+
warning(
36+
false,
3537
'transition(): tried to perform an animation without ' +
3638
'an animationend or transitionend event after timeout (' +
37-
NO_EVENT_TIMEOUT + 'ms). You should either disable this ' +
38-
'transition in JS or add a CSS animation/transition.'
39+
'%sms). You should either disable this ' +
40+
'transition in JS or add a CSS animation/transition.',
41+
NO_EVENT_TIMEOUT
3942
);
4043
};
4144
}

src/browser/ui/ReactDOMComponent.js

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ var escapeTextContentForBrowser = require('escapeTextContentForBrowser');
2929
var invariant = require('invariant');
3030
var isEventSupported = require('isEventSupported');
3131
var keyOf = require('keyOf');
32-
var monitorCodeUse = require('monitorCodeUse');
3332
var warning = require('warning');
3433

3534
var deleteListener = ReactBrowserEventEmitter.deleteListener;
@@ -74,14 +73,13 @@ function assertValidProps(props) {
7473
'Directly setting property `innerHTML` is not permitted. ' +
7574
'For more information, lookup documentation on `dangerouslySetInnerHTML`.'
7675
);
77-
if (props.contentEditable && props.children != null) {
78-
console.warn(
79-
'A component is `contentEditable` and contains `children` managed by ' +
80-
'React. It is now your responsibility to guarantee that none of ' +
81-
'those nodes are unexpectedly modified or duplicated. This is ' +
82-
'probably not intentional.'
83-
);
84-
}
76+
warning(
77+
!props.contentEditable || props.children == null,
78+
'A component is `contentEditable` and contains `children` managed by ' +
79+
'React. It is now your responsibility to guarantee that none of ' +
80+
'those nodes are unexpectedly modified or duplicated. This is ' +
81+
'probably not intentional.'
82+
);
8583
}
8684
invariant(
8785
props.style == null || typeof props.style === 'object',
@@ -95,11 +93,10 @@ function putListener(id, registrationName, listener, transaction) {
9593
if (__DEV__) {
9694
// IE8 has no API for event capturing and the `onScroll` event doesn't
9795
// bubble.
98-
if (registrationName === 'onScroll' &&
99-
!isEventSupported('scroll', true)) {
100-
monitorCodeUse('react_no_scroll_event');
101-
console.warn('This browser doesn\'t support the `onScroll` event');
102-
}
96+
warning(
97+
registrationName !== 'onScroll' || isEventSupported('scroll', true),
98+
'This browser doesn\'t support the `onScroll` event'
99+
);
103100
}
104101
var container = ReactMount.findReactContainerForID(id);
105102
if (container) {

src/browser/ui/ReactMount.js

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,8 @@ var ReactMount = {
473473
var rootElementSibling = reactRootElement;
474474
while (rootElementSibling) {
475475
if (ReactMount.isRenderedByReact(rootElementSibling)) {
476-
console.warn(
476+
warning(
477+
false,
477478
'render(): Target node has markup rendered by React, but there ' +
478479
'are unrelated nodes as well. This is most commonly caused by ' +
479480
'white-space inserted around server-rendered markup.'
@@ -648,7 +649,8 @@ var ReactMount = {
648649
// warning is when the container is empty.
649650
rootElementsByReactRootID[reactRootID] = containerChild;
650651
} else {
651-
console.warn(
652+
warning(
653+
false,
652654
'ReactMount: Root element has been removed from its original ' +
653655
'container. New container:', rootElement.parentNode
654656
);
@@ -828,15 +830,17 @@ var ReactMount = {
828830
);
829831

830832
if (__DEV__) {
831-
console.warn(
833+
warning(
834+
false,
832835
'React attempted to reuse markup in a container but the ' +
833836
'checksum was invalid. This generally means that you are ' +
834837
'using server rendering and the markup generated on the ' +
835838
'server was not what the client was expecting. React injected ' +
836839
'new markup to compensate which works but you have lost many ' +
837840
'of the benefits of server rendering. Instead, figure out ' +
838841
'why the markup being generated is different on the client ' +
839-
'or server:\n' + difference
842+
'or server:\n%s',
843+
difference
840844
);
841845
}
842846
}

src/browser/ui/__tests__/ReactDOMComponent-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ describe('ReactDOMComponent', function() {
494494
ReactTestUtils.renderIntoDocument(<div onScroll={function(){}} />);
495495
expect(console.warn.calls.length).toBe(1);
496496
expect(console.warn.mostRecentCall.args[0]).toBe(
497-
'This browser doesn\'t support the `onScroll` event'
497+
'Warning: This browser doesn\'t support the `onScroll` event'
498498
);
499499
});
500500
});

src/classic/class/ReactClass.js

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ var assign = require('Object.assign');
2424
var invariant = require('invariant');
2525
var keyMirror = require('keyMirror');
2626
var keyOf = require('keyOf');
27-
var monitorCodeUse = require('monitorCodeUse');
2827
var warning = require('warning');
2928

3029
var MIXINS_KEY = keyOf({mixins: null});
@@ -659,17 +658,19 @@ function bindAutoBindMethod(component, method) {
659658
// ignore the value of "this" that the user is trying to use, so
660659
// let's warn.
661660
if (newThis !== component && newThis !== null) {
662-
monitorCodeUse('react_bind_warning', { component: componentName });
663-
console.warn(
661+
warning(
662+
false,
664663
'bind(): React component methods may only be bound to the ' +
665-
'component instance. See ' + componentName
664+
'component instance. See %s',
665+
componentName
666666
);
667667
} else if (!args.length) {
668-
monitorCodeUse('react_bind_warning', { component: componentName });
669-
console.warn(
668+
warning(
669+
false,
670670
'bind(): You are binding a component method to the component. ' +
671671
'React does this for you automatically in a high-performance ' +
672-
'way, so you can safely remove this call. See ' + componentName
672+
'way, so you can safely remove this call. See ',
673+
componentName
673674
);
674675
return boundMethod;
675676
}
@@ -874,18 +875,14 @@ var ReactClass = {
874875
);
875876

876877
if (__DEV__) {
877-
if (Constructor.prototype.componentShouldUpdate) {
878-
monitorCodeUse(
879-
'react_component_should_update_warning',
880-
{ component: spec.displayName }
881-
);
882-
console.warn(
883-
(spec.displayName || 'A component') + ' has a method called ' +
884-
'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
885-
'The name is phrased as a question because the function is ' +
886-
'expected to return a value.'
887-
);
888-
}
878+
warning(
879+
!Constructor.prototype.componentShouldUpdate,
880+
'%s has a method called ' +
881+
'componentShouldUpdate(). Did you mean shouldComponentUpdate()? ' +
882+
'The name is phrased as a question because the function is ' +
883+
'expected to return a value.',
884+
spec.displayName || 'A component'
885+
);
889886
}
890887

891888
// Reduce time spent doing lookups by setting these on the prototype.

src/classic/class/__tests__/ReactClass-test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ describe('ReactClass-spec', function() {
170170
});
171171
expect(console.warn.argsForCall.length).toBe(1);
172172
expect(console.warn.argsForCall[0][0]).toBe(
173-
'A component has a method called componentShouldUpdate(). Did you ' +
173+
'Warning: A component has a method called componentShouldUpdate(). Did you ' +
174174
'mean shouldComponentUpdate()? The name is phrased as a question ' +
175175
'because the function is expected to return a value.'
176176
);
@@ -185,7 +185,7 @@ describe('ReactClass-spec', function() {
185185
});
186186
expect(console.warn.argsForCall.length).toBe(2);
187187
expect(console.warn.argsForCall[1][0]).toBe(
188-
'NamedComponent has a method called componentShouldUpdate(). Did you ' +
188+
'Warning: NamedComponent has a method called componentShouldUpdate(). Did you ' +
189189
'mean shouldComponentUpdate()? The name is phrased as a question ' +
190190
'because the function is expected to return a value.'
191191
);

src/classic/element/ReactElementValidator.js

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ var ReactCurrentOwner = require('ReactCurrentOwner');
2626
var ReactNativeComponent = require('ReactNativeComponent');
2727

2828
var getIteratorFn = require('getIteratorFn');
29-
var monitorCodeUse = require('monitorCodeUse');
3029
var invariant = require('invariant');
3130
var warning = require('warning');
3231

@@ -157,22 +156,17 @@ function warnAndMonitorForKeyUse(warningID, message, element, parentType) {
157156
// Usually the current owner is the offender, but if it accepts children as a
158157
// property, it may be the creator of the child that's responsible for
159158
// assigning it a key.
160-
var childOwnerName = null;
161159
if (element &&
162160
element._owner &&
163161
element._owner !== ReactCurrentOwner.current) {
164162
// Name of the component that originally created this child.
165-
childOwnerName = getName(element._owner);
163+
var childOwnerName = getName(element._owner);
166164

167165
message += ` It was passed a child from ${childOwnerName}.`;
168166
}
169167

170168
message += ' See http://fb.me/react-warning-keys for more information.';
171-
monitorCodeUse(warningID, {
172-
component: useName,
173-
componentOwner: childOwnerName
174-
});
175-
console.warn(message);
169+
warning(false, '%s', warningID + ': ' + message);
176170
}
177171

178172
/**

src/core/ReactCompositeComponent.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -588,13 +588,12 @@ var ReactCompositeComponentMixin = {
588588
inst.shouldComponentUpdate(nextProps, nextState, nextContext);
589589

590590
if (__DEV__) {
591-
if (typeof shouldUpdate === 'undefined') {
592-
console.warn(
593-
(this.getName() || 'ReactCompositeComponent') +
594-
'.shouldComponentUpdate(): Returned undefined instead of a ' +
595-
'boolean value. Make sure to return true or false.'
596-
);
597-
}
591+
warning(
592+
typeof shouldUpdate !== 'undefined',
593+
'%s.shouldComponentUpdate(): Returned undefined instead of a ' +
594+
'boolean value. Make sure to return true or false.',
595+
this.getName() || 'ReactCompositeComponent'
596+
);
598597
}
599598

600599
if (shouldUpdate) {

src/core/__tests__/ReactCompositeComponent-test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -490,7 +490,7 @@ describe('ReactCompositeComponent', function() {
490490

491491
expect(console.warn.argsForCall.length).toBe(1);
492492
expect(console.warn.argsForCall[0][0]).toBe(
493-
'Component.shouldComponentUpdate(): Returned undefined instead of a ' +
493+
'Warning: Component.shouldComponentUpdate(): Returned undefined instead of a ' +
494494
'boolean value. Make sure to return true or false.'
495495
);
496496
});

0 commit comments

Comments
 (0)