Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cherrypick warning and removal of react create class #9771

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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