From b4c541e1381d2a5e7e2bb27ae297de98e696c4b2 Mon Sep 17 00:00:00 2001 From: Flarnie Marchan Date: Tue, 30 May 2017 13:25:41 -0700 Subject: [PATCH] Improve warning for `React.createClass` (#9781) * Improve warning for `React.createClass` **what is the change?:** - Explain that this will be removed in v16.0 specifically - Mention the version number for the drop-in replacement module. - Link to docs in the blog post about how to migrate **why make this change?:** We want to make our deprecation warnings more clear and helpful. **test plan:** Visual inspection and `yarn test` **issue:** https://github.com/facebook/react/issues/9398 * Widen range of recommended replacement module versions **what is the change?:** Instead of recommending specific versions of 'prop-types' and 'create-react-class' we ask folks to use the latest available 15.* version. **why make this change?:** The latest version of those plugins, within the 15 version, is the most likely to be stable. For example, we know that 'react-create-class' is broken for AMD builds at the current latest version, so once we release a fix then the recommended version will change. **test plan:** Visual inspection Also fixed some tests. * Fix typos and things **what is the change?:** - `migrade` -> `migrate` - `15.* prop-types package` -> `v15.* prop-types package` **why make this change?:** Correctness **test plan:** `yarn test` and visual inspection --- src/isomorphic/React.js | 13 +++++++------ src/isomorphic/__tests__/React-test.js | 17 +++++++++-------- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/src/isomorphic/React.js b/src/isomorphic/React.js index d525de7a47f06..29cfea6dad024 100644 --- a/src/isomorphic/React.js +++ b/src/isomorphic/React.js @@ -112,8 +112,7 @@ if (__DEV__) { didWarnPropTypesDeprecated, '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.' + + ' Use the latest available v15.* prop-types package from npm instead.' + ' For info on usage, compatibility, migration and more, see ' + 'https://fb.me/prop-types-docs', ); @@ -126,10 +125,12 @@ if (__DEV__) { 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.', + 'Accessing createClass via the main React package is deprecated,' + + ' and will be removed in React v16.0.' + + " Use a plain JavaScript class instead. If you're not yet " + + 'ready to migrate, create-react-class v15.* is available ' + + 'on npm as a temporary, drop-in replacement. ' + + 'For more info see https://fb.me/react-create-class', ); warnedForCreateClass = true; return createReactClass; diff --git a/src/isomorphic/__tests__/React-test.js b/src/isomorphic/__tests__/React-test.js index 9cd9ebb18af78..7a2d0c9ac9d6e 100644 --- a/src/isomorphic/__tests__/React-test.js +++ b/src/isomorphic/__tests__/React-test.js @@ -45,10 +45,12 @@ describe('React', () => { 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.', + 'Warning: Accessing createClass via the main React package is ' + + 'deprecated, and will be removed in React v16.0. ' + + "Use a plain JavaScript class instead. If you're not yet ready " + + 'to migrate, create-react-class v15.* is available on npm as ' + + 'a temporary, drop-in replacement. ' + + 'For more info see https://fb.me/react-create-class', ); }); @@ -61,10 +63,9 @@ describe('React', () => { 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', + 'Use the latest available v15.* prop-types package from ' + + 'npm instead. For info on usage, compatibility, migration ' + + 'and more, see https://fb.me/prop-types-docs', ); }); });