Skip to content

Commit ad3c5d3

Browse files
committed
Downgrade deprecation warnings from errors to warnings
**what is the change?:** Swapping out `warning` module for a fork that uses `console.warn`. It looks like we were using the `warning` module for deprecation notices, *but* there is also a 'deprecated' module designed specifically for deprecation notices. However, we could not find any place that it was currently used. Since React's build process is not 100% clear to me, I assume it could still be used somewhere by something and just updated it along with other deprecation notices. We might consider a follow-up diff that does some clean up here; - remove 'deprecated' module if it's unused, OR - use 'deprecated' module for all our current deprecation warnings **why make this change?:** - We have had complaints about noisy warnings, in particular after introducing new deprecations - They potentially cause CI failures - Deprecations are not really time-sensitive, can ship without breaking your app, etc. For more context - facebook#9395 **test plan:** `npm run test` and unit tests for the new modules and manual testing (WIP) **issue:** facebook#9395
1 parent 76f0c41 commit ad3c5d3

16 files changed

+109
-63
lines changed

src/addons/__tests__/ReactDOMFactories-test.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,24 @@ var {div} = require('ReactDOMFactories');
1717
describe('ReactDOMFactories', () => {
1818
it('allow factories to be called without warnings', () => {
1919
spyOn(console, 'error');
20+
spyOn(console, 'warn');
2021
var element = div();
2122
expect(element.type).toBe('div');
2223
expect(console.error).not.toHaveBeenCalled();
24+
expect(console.warn).not.toHaveBeenCalled();
2325
});
2426

2527
it('warns once when accessing React.DOM methods', () => {
26-
spyOn(console, 'error');
28+
spyOn(console, 'warn');
2729

2830
var a = React.DOM.a();
2931
var p = React.DOM.p();
3032

3133
expect(a.type).toBe('a');
3234
expect(p.type).toBe('p');
3335

34-
expect(console.error).toHaveBeenCalledTimes(1);
35-
expect(console.error.calls.first().args[0]).toContain(
36+
expect(console.warn).toHaveBeenCalledTimes(1);
37+
expect(console.warn.calls.first().args[0]).toContain(
3638
'Warning: Accessing factories like React.DOM.a has been deprecated',
3739
);
3840
});

src/isomorphic/React.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var createFactory = ReactElement.createFactory;
2727
var cloneElement = ReactElement.cloneElement;
2828

2929
if (__DEV__) {
30-
var warning = require('fbjs/lib/warning');
30+
var lowPriorityWarning = require('lowPriorityWarning');
3131
var canDefineProperty = require('canDefineProperty');
3232
var ReactElementValidator = require('ReactElementValidator');
3333
createElement = ReactElementValidator.createElement;
@@ -91,7 +91,7 @@ if (__DEV__) {
9191
let warnedForPropTypes = false;
9292

9393
React.createMixin = function(mixin) {
94-
warning(
94+
lowPriorityWarning(
9595
warnedForCreateMixin,
9696
'React.createMixin is deprecated and should not be used. You ' +
9797
'can use this mixin directly instead.',
@@ -104,7 +104,7 @@ if (__DEV__) {
104104
if (canDefineProperty) {
105105
Object.defineProperty(React, 'checkPropTypes', {
106106
get() {
107-
warning(
107+
lowPriorityWarning(
108108
warnedForCheckPropTypes,
109109
'checkPropTypes has been moved to a separate package. ' +
110110
'Accessing React.checkPropTypes is no longer supported ' +
@@ -119,7 +119,7 @@ if (__DEV__) {
119119

120120
Object.defineProperty(React, 'createClass', {
121121
get: function() {
122-
warning(
122+
lowPriorityWarning(
123123
warnedForCreateClass,
124124
'React.createClass is no longer supported. Use a plain JavaScript ' +
125125
"class instead. If you're not yet ready to migrate, " +
@@ -133,7 +133,7 @@ if (__DEV__) {
133133

134134
Object.defineProperty(React, 'PropTypes', {
135135
get() {
136-
warning(
136+
lowPriorityWarning(
137137
warnedForPropTypes,
138138
'PropTypes has been moved to a separate package. ' +
139139
'Accessing React.PropTypes is no longer supported ' +
@@ -155,7 +155,7 @@ if (__DEV__) {
155155
Object.keys(ReactDOMFactories).forEach(function(factory) {
156156
React.DOM[factory] = function(...args) {
157157
if (!warnedForFactories) {
158-
warning(
158+
lowPriorityWarning(
159159
false,
160160
'Accessing factories like React.DOM.%s has been deprecated ' +
161161
'and will be removed in the future. Use the ' +

src/isomorphic/__tests__/React-test.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ describe('React', () => {
1919
});
2020

2121
it('should log a deprecation warning once when using React.createMixin', () => {
22-
spyOn(console, 'error');
22+
spyOn(console, 'warn');
2323
React.createMixin();
2424
React.createMixin();
25-
expectDev(console.error.calls.count()).toBe(1);
26-
expectDev(console.error.calls.argsFor(0)[0]).toContain(
25+
expectDev(console.warn.calls.count()).toBe(1);
26+
expectDev(console.warn.calls.argsFor(0)[0]).toContain(
2727
'React.createMixin is deprecated and should not be used',
2828
);
2929
});
3030

3131
it('should warn once when attempting to access React.createClass', () => {
32-
spyOn(console, 'error');
32+
spyOn(console, 'warn');
3333
let createClass = React.createClass;
3434
createClass = React.createClass;
3535
expect(createClass).not.toBe(undefined);
36-
expectDev(console.error.calls.count()).toBe(1);
37-
expectDev(console.error.calls.argsFor(0)[0]).toContain(
36+
expectDev(console.warn.calls.count()).toBe(1);
37+
expectDev(console.warn.calls.argsFor(0)[0]).toContain(
3838
'React.createClass is no longer supported. Use a plain JavaScript ' +
3939
"class instead. If you're not yet ready to migrate, " +
4040
'create-react-class is available on npm as a drop-in replacement. ' +
@@ -43,12 +43,12 @@ describe('React', () => {
4343
});
4444

4545
it('should warn once when attempting to access React.PropTypes', () => {
46-
spyOn(console, 'error');
46+
spyOn(console, 'warn');
4747
let PropTypes = React.PropTypes;
4848
PropTypes = React.PropTypes;
4949
expect(PropTypes).not.toBe(undefined);
50-
expectDev(console.error.calls.count()).toBe(1);
51-
expectDev(console.error.calls.argsFor(0)[0]).toContain(
50+
expectDev(console.warn.calls.count()).toBe(1);
51+
expectDev(console.warn.calls.argsFor(0)[0]).toContain(
5252
'PropTypes has been moved to a separate package. ' +
5353
'Accessing React.PropTypes is no longer supported ' +
5454
'and will be removed completely in React 16. ' +
@@ -58,12 +58,12 @@ describe('React', () => {
5858
});
5959

6060
it('should warn once when attempting to access React.checkPropTypes', () => {
61-
spyOn(console, 'error');
61+
spyOn(console, 'warn');
6262
let checkPropTypes = React.checkPropTypes;
6363
checkPropTypes = React.checkPropTypes;
6464
expect(checkPropTypes).not.toBe(undefined);
65-
expectDev(console.error.calls.count()).toBe(1);
66-
expectDev(console.error.calls.argsFor(0)[0]).toContain(
65+
expectDev(console.warn.calls.count()).toBe(1);
66+
expectDev(console.warn.calls.argsFor(0)[0]).toContain(
6767
'checkPropTypes has been moved to a separate package. ' +
6868
'Accessing React.checkPropTypes is no longer supported ' +
6969
'and will be removed completely in React 16. ' +

src/isomorphic/classic/element/ReactElementValidator.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ var getIteratorFn = require('getIteratorFn');
2727

2828
if (__DEV__) {
2929
var checkPropTypes = require('prop-types/checkPropTypes');
30-
var warning = require('fbjs/lib/warning');
30+
var lowPriorityWarning = require('lowPriorityWarning');
3131
var ReactDebugCurrentFrame = require('ReactDebugCurrentFrame');
32+
var warning = require('fbjs/lib/warning');
3233
var {getCurrentStackAddendum} = require('ReactComponentTreeHook');
3334
}
3435

@@ -285,7 +286,7 @@ var ReactElementValidator = {
285286
Object.defineProperty(validatedFactory, 'type', {
286287
enumerable: false,
287288
get: function() {
288-
warning(
289+
lowPriorityWarning(
289290
false,
290291
'Factory.type is deprecated. Access the class directly ' +
291292
'before passing it to createFactory.',

src/isomorphic/classic/element/__tests__/ReactElementValidator-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,20 +441,20 @@ describe('ReactElementValidator', () => {
441441
});
442442

443443
it('should warn when accessing .type on an element factory', () => {
444-
spyOn(console, 'error');
444+
spyOn(console, 'warn');
445445
function TestComponent() {
446446
return <div />;
447447
}
448448
var TestFactory = React.createFactory(TestComponent);
449449
expect(TestFactory.type).toBe(TestComponent);
450-
expectDev(console.error.calls.count()).toBe(1);
451-
expectDev(console.error.calls.argsFor(0)[0]).toBe(
450+
expectDev(console.warn.calls.count()).toBe(1);
451+
expectDev(console.warn.calls.argsFor(0)[0]).toBe(
452452
'Warning: Factory.type is deprecated. Access the class directly before ' +
453453
'passing it to createFactory.',
454454
);
455455
// Warn once, not again
456456
expect(TestFactory.type).toBe(TestComponent);
457-
expectDev(console.error.calls.count()).toBe(1);
457+
expectDev(console.warn.calls.count()).toBe(1);
458458
});
459459

460460
it('does not warn when using DOM node as children', () => {

src/isomorphic/modern/class/ReactBaseClasses.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var ReactNoopUpdateQueue = require('ReactNoopUpdateQueue');
1616
var canDefineProperty = require('canDefineProperty');
1717
var emptyObject = require('fbjs/lib/emptyObject');
1818
var invariant = require('fbjs/lib/invariant');
19-
var warning = require('fbjs/lib/warning');
19+
var lowPriorityWarning = require('lowPriorityWarning');
2020

2121
/**
2222
* Base class helpers for the updating state of a component.
@@ -108,7 +108,7 @@ if (__DEV__) {
108108
if (canDefineProperty) {
109109
Object.defineProperty(ReactComponent.prototype, methodName, {
110110
get: function() {
111-
warning(
111+
lowPriorityWarning(
112112
false,
113113
'%s(...) is deprecated in plain JavaScript React classes. %s',
114114
info[0],

src/isomorphic/modern/class/__tests__/ReactCoffeeScriptClass-test.coffee

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,16 +378,16 @@ describe 'ReactCoffeeScriptClass', ->
378378
undefined
379379

380380
it 'should throw AND warn when trying to access classic APIs', ->
381-
spyOn console, 'error'
381+
spyOn console, 'warn'
382382
instance =
383383
test Inner(name: 'foo'), 'DIV', 'foo'
384384
expect(-> instance.replaceState {}).toThrow()
385385
expect(-> instance.isMounted()).toThrow()
386-
expect(console.error.calls.count()).toBe 2
387-
expect(console.error.calls.argsFor(0)[0]).toContain(
386+
expect(console.warn.calls.count()).toBe 2
387+
expect(console.warn.calls.argsFor(0)[0]).toContain(
388388
'replaceState(...) is deprecated in plain JavaScript React classes'
389389
)
390-
expect(console.error.calls.argsFor(1)[0]).toContain(
390+
expect(console.warn.calls.argsFor(1)[0]).toContain(
391391
'isMounted(...) is deprecated in plain JavaScript React classes'
392392
)
393393
undefined

src/isomorphic/modern/class/__tests__/ReactES6Class-test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -402,15 +402,15 @@ describe('ReactES6Class', () => {
402402
});
403403

404404
it('should throw AND warn when trying to access classic APIs', () => {
405-
spyOn(console, 'error');
405+
spyOn(console, 'warn');
406406
var instance = test(<Inner name="foo" />, 'DIV', 'foo');
407407
expect(() => instance.replaceState({})).toThrow();
408408
expect(() => instance.isMounted()).toThrow();
409-
expect(console.error.calls.count()).toBe(2);
410-
expect(console.error.calls.argsFor(0)[0]).toContain(
409+
expect(console.warn.calls.count()).toBe(2);
410+
expect(console.warn.calls.argsFor(0)[0]).toContain(
411411
'replaceState(...) is deprecated in plain JavaScript React classes',
412412
);
413-
expect(console.error.calls.argsFor(1)[0]).toContain(
413+
expect(console.warn.calls.argsFor(1)[0]).toContain(
414414
'isMounted(...) is deprecated in plain JavaScript React classes',
415415
);
416416
});

src/isomorphic/modern/class/__tests__/ReactTypeScriptClass-test.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -502,18 +502,18 @@ describe('ReactTypeScriptClass', function() {
502502
});
503503

504504
it('should throw AND warn when trying to access classic APIs', function() {
505-
spyOn(console, 'error');
505+
spyOn(console, 'warn');
506506
var instance = test(
507507
React.createElement(Inner, {name: 'foo'}),
508508
'DIV','foo'
509509
);
510510
expect(() => instance.replaceState({})).toThrow();
511511
expect(() => instance.isMounted()).toThrow();
512-
expect((<any>console.error).calls.count()).toBe(2);
513-
expect((<any>console.error).calls.argsFor(0)[0]).toContain(
512+
expect((<any>console.warn).calls.count()).toBe(2);
513+
expect((<any>console.warn).calls.argsFor(0)[0]).toContain(
514514
'replaceState(...) is deprecated in plain JavaScript React classes'
515515
);
516-
expect((<any>console.error).calls.argsFor(1)[0]).toContain(
516+
expect((<any>console.warn).calls.argsFor(1)[0]).toContain(
517517
'isMounted(...) is deprecated in plain JavaScript React classes'
518518
);
519519
});

src/renderers/__tests__/ReactCompositeComponentState-test.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ describe('ReactCompositeComponent-state', () => {
405405
});
406406

407407
it('should treat assigning to this.state inside cWRP as a replaceState, with a warning', () => {
408-
spyOn(console, 'error');
408+
spyOn(console, 'warn');
409409

410410
let ops = [];
411411
class Test extends React.Component {
@@ -439,8 +439,8 @@ describe('ReactCompositeComponent-state', () => {
439439
'render -- step: 3, extra: false',
440440
'callback -- step: 3, extra: false',
441441
]);
442-
expect(console.error.calls.count()).toEqual(1);
443-
expect(console.error.calls.argsFor(0)[0]).toEqual(
442+
expect(console.warn.calls.count()).toEqual(1);
443+
expect(console.warn.calls.argsFor(0)[0]).toEqual(
444444
'Warning: Test.componentWillReceiveProps(): Assigning directly to ' +
445445
"this.state is deprecated (except inside a component's constructor). " +
446446
'Use setState instead.',
@@ -449,7 +449,7 @@ describe('ReactCompositeComponent-state', () => {
449449

450450
if (ReactDOMFeatureFlags.useFiber) {
451451
it('should treat assigning to this.state inside cWM as a replaceState, with a warning', () => {
452-
spyOn(console, 'error');
452+
spyOn(console, 'warn');
453453

454454
let ops = [];
455455
class Test extends React.Component {
@@ -480,8 +480,8 @@ describe('ReactCompositeComponent-state', () => {
480480
'render -- step: 3, extra: false',
481481
'callback -- step: 3, extra: false',
482482
]);
483-
expect(console.error.calls.count()).toEqual(1);
484-
expect(console.error.calls.argsFor(0)[0]).toEqual(
483+
expect(console.warn.calls.count()).toEqual(1);
484+
expect(console.warn.calls.argsFor(0)[0]).toEqual(
485485
'Warning: Test.componentWillMount(): Assigning directly to ' +
486486
"this.state is deprecated (except inside a component's constructor). " +
487487
'Use setState instead.',

src/renderers/__tests__/ReactPerf-test.js

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -406,30 +406,30 @@ describeStack('ReactPerf', () => {
406406

407407
it('warns once when using getMeasurementsSummaryMap', () => {
408408
var measurements = measure(() => {});
409-
spyOn(console, 'error');
409+
spyOn(console, 'warn');
410410
ReactPerf.getMeasurementsSummaryMap(measurements);
411-
expectDev(console.error.calls.count()).toBe(1);
412-
expectDev(console.error.calls.argsFor(0)[0]).toContain(
411+
expectDev(console.warn.calls.count()).toBe(1);
412+
expectDev(console.warn.calls.argsFor(0)[0]).toContain(
413413
'`ReactPerf.getMeasurementsSummaryMap(...)` is deprecated. Use ' +
414414
'`ReactPerf.getWasted(...)` instead.',
415415
);
416416

417417
ReactPerf.getMeasurementsSummaryMap(measurements);
418-
expectDev(console.error.calls.count()).toBe(1);
418+
expectDev(console.warn.calls.count()).toBe(1);
419419
});
420420

421421
it('warns once when using printDOM', () => {
422422
var measurements = measure(() => {});
423-
spyOn(console, 'error');
423+
spyOn(console, 'warn');
424424
ReactPerf.printDOM(measurements);
425-
expectDev(console.error.calls.count()).toBe(1);
426-
expectDev(console.error.calls.argsFor(0)[0]).toContain(
425+
expectDev(console.warn.calls.count()).toBe(1);
426+
expectDev(console.warn.calls.argsFor(0)[0]).toContain(
427427
'`ReactPerf.printDOM(...)` is deprecated. Use ' +
428428
'`ReactPerf.printOperations(...)` instead.',
429429
);
430430

431431
ReactPerf.printDOM(measurements);
432-
expectDev(console.error.calls.count()).toBe(1);
432+
expectDev(console.warn.calls.count()).toBe(1);
433433
});
434434

435435
it('returns isRunning state', () => {

src/renderers/shared/ReactPerf.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
'use strict';
1414

1515
var ReactDebugTool = require('ReactDebugTool');
16-
var warning = require('fbjs/lib/warning');
16+
var lowPriorityWarning = require('lowPriorityWarning');
1717
var alreadyWarned = false;
1818

1919
import type {FlushHistory} from 'ReactDebugTool';
@@ -390,7 +390,7 @@ function printOperations(flushHistory?: FlushHistory) {
390390

391391
var warnedAboutPrintDOM = false;
392392
function printDOM(measurements: FlushHistory) {
393-
warning(
393+
lowPriorityWarning(
394394
warnedAboutPrintDOM,
395395
'`ReactPerf.printDOM(...)` is deprecated. Use ' +
396396
'`ReactPerf.printOperations(...)` instead.',
@@ -401,7 +401,7 @@ function printDOM(measurements: FlushHistory) {
401401

402402
var warnedAboutGetMeasurementsSummaryMap = false;
403403
function getMeasurementsSummaryMap(measurements: FlushHistory) {
404-
warning(
404+
lowPriorityWarning(
405405
warnedAboutGetMeasurementsSummaryMap,
406406
'`ReactPerf.getMeasurementsSummaryMap(...)` is deprecated. Use ' +
407407
'`ReactPerf.getWasted(...)` instead.',

0 commit comments

Comments
 (0)