Skip to content

Commit 8fee440

Browse files
committed
Cherrypick warning and removal of react create class (facebook#9771)
* react-create-class -> create-react-class * Fix issues/bugs introduced by merge conflict resolution **what is the change?:** A couple of bugs and holes were introduced when cherry-picking facebook#9232 onto the 15.6 branch. This fixes them. We also needed to add some logic from facebook#9399 **why make this change?:** To keep tests passing and get this change working. **test plan:** `yarn test` **issue:** facebook#9398 * Move component base classes into a single file (facebook#8918) * More fixes for issues introduced by rebasing **what is the change?:** - Remove some outdated 'require' statements that got orphaned in 'React.js' - Change 'warning' to 'lowPriorityWarning' for 'React.createClass' - Fix syntax issues in 'React-test' - Use 'creatReactClass' instead of ES6 class in ReactART - Update 'prop-type' dependency to use no higher than 15.7 because 15.8 limits the number of warnings, and this causes a test to fail. - Fix some mixed-up and misnamed variables in `React.js` - Rebase onto commit that updates deprecation messages - Update a test based on new deprecation messages **why make this change?:** These were bugs introduced by rebasing and tests caught the regressions. **test plan:** `yarn test` **issue:** facebook#9398 * Reset `yarn.lock` **what is the change?:** I didn't mean to commit changes to `yarn.lock` except for the `prop-types` and `create-react-class` updates. **why make this change?:** To minimize the changes we make to dependency versions. **test plan:** `rm -rf node_modules` `yarn install` `yarn run build` `yarn test` * Run `yarn prettier`
1 parent cc89cf5 commit 8fee440

File tree

11 files changed

+225
-989
lines changed

11 files changed

+225
-989
lines changed

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"coffee-script": "^1.8.0",
4141
"core-js": "^2.2.1",
4242
"coveralls": "^2.11.6",
43-
"create-react-class": "15.5.0",
4443
"del": "^2.0.2",
4544
"derequire": "^2.0.3",
4645
"eslint": "^3.10.2",
@@ -72,7 +71,6 @@
7271
"object-assign": "^4.1.1",
7372
"platform": "^1.1.0",
7473
"prettier": "^1.2.2",
75-
"prop-types": "15.5.7",
7674
"run-sequence": "^1.1.4",
7775
"through2": "^2.0.0",
7876
"tmp": "~0.0.28",
@@ -85,6 +83,10 @@
8583
"node": "4.x || 5.x || 6.x || 7.x",
8684
"npm": "2.x || 3.x || 4.x"
8785
},
86+
"dependencies": {
87+
"create-react-class": "^15.5.2",
88+
"prop-types": "15.5.7"
89+
},
8890
"commonerConfig": {
8991
"version": 7
9092
},

src/isomorphic/React.js

+20-7
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@
1111

1212
'use strict';
1313

14+
var ReactBaseClasses = require('ReactBaseClasses');
1415
var ReactChildren = require('ReactChildren');
15-
var ReactComponent = require('ReactComponent');
16-
var ReactPureComponent = require('ReactPureComponent');
17-
var ReactClass = require('ReactClass');
1816
var ReactDOMFactories = require('ReactDOMFactories');
1917
var ReactElement = require('ReactElement');
2018
var ReactPropTypes = require('ReactPropTypes');
2119
var ReactVersion = require('ReactVersion');
2220

21+
var createReactClass = require('createClass');
2322
var onlyChild = require('onlyChild');
2423

2524
var createElement = ReactElement.createElement;
@@ -80,8 +79,8 @@ var React = {
8079
only: onlyChild,
8180
},
8281

83-
Component: ReactComponent,
84-
PureComponent: ReactPureComponent,
82+
Component: ReactBaseClasses.Component,
83+
PureComponent: ReactBaseClasses.PureComponent,
8584

8685
createElement: createElement,
8786
cloneElement: cloneElement,
@@ -90,7 +89,7 @@ var React = {
9089
// Classic
9190

9291
PropTypes: ReactPropTypes,
93-
createClass: ReactClass.createClass,
92+
createClass: createReactClass,
9493
createFactory: createFactory,
9594
createMixin: createMixin,
9695

@@ -104,8 +103,8 @@ var React = {
104103
__spread: __spread,
105104
};
106105

107-
// TODO: Fix tests so that this deprecation warning doesn't cause failures.
108106
if (__DEV__) {
107+
let warnedForCreateClass = false;
109108
if (canDefineProperty) {
110109
Object.defineProperty(React, 'PropTypes', {
111110
get() {
@@ -122,6 +121,20 @@ if (__DEV__) {
122121
return ReactPropTypes;
123122
},
124123
});
124+
125+
Object.defineProperty(React, 'createClass', {
126+
get: function() {
127+
lowPriorityWarning(
128+
warnedForCreateClass,
129+
'React.createClass is no longer supported. Use a plain JavaScript ' +
130+
"class instead. If you're not yet ready to migrate, " +
131+
'create-react-class is available on npm as a temporary, ' +
132+
'drop-in replacement.',
133+
);
134+
warnedForCreateClass = true;
135+
return createReactClass;
136+
},
137+
});
125138
}
126139

127140
// React.DOM factories are deprecated. Wrap these methods so that

src/isomorphic/__tests__/React-test.js

+30
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,34 @@ describe('React', () => {
3737
'React.createMixin is deprecated and should not be used',
3838
);
3939
});
40+
41+
it('should warn once when attempting to access React.createClass', () => {
42+
spyOn(console, 'warn');
43+
let createClass = React.createClass;
44+
createClass = React.createClass;
45+
expect(createClass).not.toBe(undefined);
46+
expect(console.warn.calls.count()).toBe(1);
47+
expect(console.warn.calls.argsFor(0)[0]).toContain(
48+
'React.createClass is no longer supported. Use a plain ' +
49+
"JavaScript class instead. If you're not yet ready to migrate, " +
50+
'create-react-class is available on npm as a temporary, ' +
51+
'drop-in replacement.',
52+
);
53+
});
54+
55+
it('should warn once when attempting to access React.PropTypes', () => {
56+
spyOn(console, 'warn');
57+
let PropTypes = React.PropTypes;
58+
PropTypes = React.PropTypes;
59+
expect(PropTypes).not.toBe(undefined);
60+
expect(console.warn.calls.count()).toBe(1);
61+
expect(console.warn.calls.argsFor(0)[0]).toContain(
62+
'Warning: Accessing PropTypes via the main React package is ' +
63+
'deprecated, and will be removed in React v16.0. ' +
64+
'Use the prop-types package from npm instead. ' +
65+
'Version 15.5.10 provides a drop-in replacement. ' +
66+
'For info on usage, compatibility, migration and more, ' +
67+
'see https://fb.me/prop-types-docs',
68+
);
69+
});
4070
});

0 commit comments

Comments
 (0)