Skip to content

Commit

Permalink
Cherrypick warning and removal of react create class (facebook#9771)
Browse files Browse the repository at this point in the history
* 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`
  • Loading branch information
flarnie committed Jun 7, 2017
1 parent cc89cf5 commit 8fee440
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 989 deletions.
6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"coffee-script": "^1.8.0",
"core-js": "^2.2.1",
"coveralls": "^2.11.6",
"create-react-class": "15.5.0",
"del": "^2.0.2",
"derequire": "^2.0.3",
"eslint": "^3.10.2",
Expand Down Expand Up @@ -72,7 +71,6 @@
"object-assign": "^4.1.1",
"platform": "^1.1.0",
"prettier": "^1.2.2",
"prop-types": "15.5.7",
"run-sequence": "^1.1.4",
"through2": "^2.0.0",
"tmp": "~0.0.28",
Expand All @@ -85,6 +83,10 @@
"node": "4.x || 5.x || 6.x || 7.x",
"npm": "2.x || 3.x || 4.x"
},
"dependencies": {
"create-react-class": "^15.5.2",
"prop-types": "15.5.7"
},
"commonerConfig": {
"version": 7
},
Expand Down
27 changes: 20 additions & 7 deletions src/isomorphic/React.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@

'use strict';

var ReactBaseClasses = require('ReactBaseClasses');
var ReactChildren = require('ReactChildren');
var ReactComponent = require('ReactComponent');
var ReactPureComponent = require('ReactPureComponent');
var ReactClass = require('ReactClass');
var ReactDOMFactories = require('ReactDOMFactories');
var ReactElement = require('ReactElement');
var ReactPropTypes = require('ReactPropTypes');
var ReactVersion = require('ReactVersion');

var createReactClass = require('createClass');
var onlyChild = require('onlyChild');

var createElement = ReactElement.createElement;
Expand Down Expand Up @@ -80,8 +79,8 @@ var React = {
only: onlyChild,
},

Component: ReactComponent,
PureComponent: ReactPureComponent,
Component: ReactBaseClasses.Component,
PureComponent: ReactBaseClasses.PureComponent,

createElement: createElement,
cloneElement: cloneElement,
Expand All @@ -90,7 +89,7 @@ var React = {
// Classic

PropTypes: ReactPropTypes,
createClass: ReactClass.createClass,
createClass: createReactClass,
createFactory: createFactory,
createMixin: createMixin,

Expand All @@ -104,8 +103,8 @@ var React = {
__spread: __spread,
};

// TODO: Fix tests so that this deprecation warning doesn't cause failures.
if (__DEV__) {
let warnedForCreateClass = false;
if (canDefineProperty) {
Object.defineProperty(React, 'PropTypes', {
get() {
Expand All @@ -122,6 +121,20 @@ if (__DEV__) {
return ReactPropTypes;
},
});

Object.defineProperty(React, 'createClass', {
get: function() {
lowPriorityWarning(
warnedForCreateClass,
'React.createClass is no longer supported. Use a plain JavaScript ' +
"class instead. If you're not yet ready to migrate, " +
'create-react-class is available on npm as a temporary, ' +
'drop-in replacement.',
);
warnedForCreateClass = true;
return createReactClass;
},
});
}

// React.DOM factories are deprecated. Wrap these methods so that
Expand Down
30 changes: 30 additions & 0 deletions src/isomorphic/__tests__/React-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,34 @@ describe('React', () => {
'React.createMixin is deprecated and should not be used',
);
});

it('should warn once when attempting to access React.createClass', () => {
spyOn(console, 'warn');
let createClass = React.createClass;
createClass = React.createClass;
expect(createClass).not.toBe(undefined);
expect(console.warn.calls.count()).toBe(1);
expect(console.warn.calls.argsFor(0)[0]).toContain(
'React.createClass is no longer supported. Use a plain ' +
"JavaScript class instead. If you're not yet ready to migrate, " +
'create-react-class is available on npm as a temporary, ' +
'drop-in replacement.',
);
});

it('should warn once when attempting to access React.PropTypes', () => {
spyOn(console, 'warn');
let PropTypes = React.PropTypes;
PropTypes = React.PropTypes;
expect(PropTypes).not.toBe(undefined);
expect(console.warn.calls.count()).toBe(1);
expect(console.warn.calls.argsFor(0)[0]).toContain(
'Warning: Accessing PropTypes via the main React package is ' +
'deprecated, and will be removed in React v16.0. ' +
'Use the prop-types package from npm instead. ' +
'Version 15.5.10 provides a drop-in replacement. ' +
'For info on usage, compatibility, migration and more, ' +
'see https://fb.me/prop-types-docs',
);
});
});
Loading

0 comments on commit 8fee440

Please sign in to comment.