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

createClass + PropTypes + checkPropTypes warnings #9399

Merged
merged 11 commits into from
Apr 11, 2017

Conversation

bvaughn
Copy link
Contributor

@bvaughn bvaughn commented Apr 11, 2017

This PR is prep work for a new 16 alpha release that (temporarily) re-adds getters with deprecation warnings for React.PropTypes, React.checkPropTypes, and React.createClass. I'm hoping to get this new alpha cherry picked into RN 44.

I've broken this PR into multiple commits to make it easier to review:

  • 08bd020: Replace all references to React.PropTypes with prop-types to avoid triggering our own warning message.
  • ef5b5c6: Removed several references to React.createClass that appeared after rebasing this branch. (reviewed by @flarnie)
  • 524ce20: Added getters for createClass and PropTypes to the main React isomorphic object, behind one-time warning messages. (reviewed by @spicyj)
  • db48f54: Fixed Rollup bundles to inline 'prop-types' and 'create-react-class' for UMD builds only. (reviewed by @spicyj, @trueadm )
  • cf49cfd: Updated tests-passing.txt to remove tests that were deleted in this branch.
  • d34109a: Responses to PR feedback from @spicyj. (Added package.json dependencies to packages/react and packages/react-dom. Renamed a var. Expanded on an inline comment.)
  • 488c8d2: Added warning for moved package to React.checkPropTypes accessor too and updated build script.
  • 83bcb29: Wordsmithing for deprecation notices (added fb.me links).
  • afdc9d2: Tweaked legacy module inlining to remove order-of-deps constraint
  • d1348b9: Removed $FlowFixMe.
  • 7dbc3e7: More wordsmithing of deprecation notices based on Dan's feedback.

@bvaughn bvaughn requested a review from acdlite April 11, 2017 00:38
@bvaughn bvaughn force-pushed the prop-types branch 4 times, most recently from 2b2237f to 5006ec8 Compare April 11, 2017 04:38
@bvaughn bvaughn changed the title Remove React.PropTypes references in favor of prop-types [WIP] Remove React.PropTypes references in favor of prop-types Apr 11, 2017
@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 11, 2017

Should be ready for review, @acdlite

@flarnie
Copy link
Contributor

flarnie commented Apr 11, 2017

"Fixed several createClass references in fixtures" lgtm - reviewing the other change now.

@bvaughn bvaughn changed the title Remove React.PropTypes references in favor of prop-types PropTypes and createClass adjustments Apr 11, 2017
Copy link
Collaborator

@sophiebits sophiebits left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed "Added getters" and "Fixed rollup" only. I don't think I fully understand how everything fits together but trust that you do if my questions don't make you unsure. :)

package.json Outdated
@@ -95,6 +93,10 @@
"node": "4.x || 5.x || 6.x || 7.x",
"npm": "2.x || 3.x || 4.x"
},
"dependencies": {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you move these? I think dev should be fine. This package.json is only used for development; we have others for the npm packages that get released.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

D'oh! Habit. I'll undo this change and update the packages/*/package.json files instead 😄

externals: [
'create-react-class/factory',
'prop-types',
'prop-types/checkPropTypes',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does only isomorphic use checkPropTypes like this? I guess I would have thought that context type checking does too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DOM does check too but it uses React.checkPropTypes. Rollup also only complained about the externals reference for isomorphic.

Object.defineProperty(React, 'PropTypes', {
get() {
warning(
didWarnPropTypesDeprecated,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: inconsistent naming with this and warnedForCreateClass

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add something like "it will be removed completely in React 16"

Also, maybe we could make this warning and the one for React.createClass more consistent.

@@ -52,6 +52,17 @@ const devOnlyFilesToStubOut = [
"'ReactTestUtils'",
];

// Ordering of these imports is important;
// The default import must follow deep imports or Rollup breaks.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why does Rollup break? (This seems brittle.)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave an example below (in the comments) of what it maps the requires to but I'll update it to be a bit more explicit. Basically if it partial-matches one of the keys (eg prop-types/checkPropTypes matches prop-types) then it stops searching and uses a path like prop-types/index.js/checkPropTypes.js

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't this mean that the replacement logic misses ' or something that delimits end of the string, and we should add that?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaearon I added a comment below, we don't need this logic here :) this should address what @spicyj said as well

1) Added dependencies for create-react-class/prop-types to packages/react*/package.json
2) Renamed a warning let
3) Expanded on an inline comment example
@bvaughn bvaughn requested review from gaearon and trueadm April 11, 2017 18:14
case UMD_DEV:
case UMD_PROD:
const modulesAlias = {};
for (var legacyModule in legacyModules) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: can we use const or let here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup!

Copy link
Contributor

@trueadm trueadm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked over the Rollup still, it all looks good (the nit isn't important)

@bvaughn bvaughn changed the title PropTypes and createClass adjustments createClass + PropTypes + checkPropTypes warnings Apr 11, 2017
Object.defineProperty(React, 'PropTypes', {
get() {
warning(
didWarnPropTypesDeprecated,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's add something like "it will be removed completely in React 16"

Also, maybe we could make this warning and the one for React.createClass more consistent.

warning(
warnedForPropTypes,
'PropTypes have moved out of the react package. ' +
'Use the prop-types package from npm instead.',
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggestion:

PropTypes have been moved to a separate package. Accessing React.PropTypes is no longer supported, and will be removed completely in React 16. Use the prop-types package on npm instead.

Copy link
Collaborator

@acdlite acdlite Apr 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And then with a link with more explanation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sweet. Will do.

@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 11, 2017

Added wordsmithing suggestions in 83bcb29 @acdlite

case UMD_PROD:
const modulesAlias = {};
for (var legacyModule in legacyModules) {
modulesAlias[legacyModule] = resolve(
Copy link
Contributor

@trueadm trueadm Apr 11, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per @gaearon's point above, if we put quotes around this, so it's moduleAlias[`'${legacyModule}'`] then the legacyModule order shouldn't matter as the replace module literally "just" does string replacement :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! I'll try that. 😁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed in afdc9d2.

@bvaughn
Copy link
Contributor Author

bvaughn commented Apr 11, 2017

Tagging @acdlite to review 488c8d2 and 83bcb29
Tagging @trueadm to review afdc9d2

@@ -106,8 +106,11 @@ if (__DEV__) {
get() {
warning(
warnedForCheckPropTypes,
'checkPropTypes has moved out of the react package. ' +
'Use the prop-types package from npm instead.',
'checkPropTypes have been moved to a separate package. ' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not "has been"?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Words are hard 😅

'create-react-class is available on npm as a temporary, ' +
'drop-in replacement.',
'drop-in replacement. ' +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we make it clear it will keep on working indefinitely? "temporary" doesn't sound very reassuring.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah totally. I'll remove the word "temporary"

@bvaughn bvaughn merged commit 2beec2f into facebook:master Apr 11, 2017
@bvaughn bvaughn deleted the prop-types branch April 11, 2017 21:28
flarnie added a commit to flarnie/react that referenced this pull request May 25, 2017
**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
flarnie added a commit to flarnie/react that referenced this pull request May 25, 2017
**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
flarnie added a commit that referenced this pull request May 25, 2017
* 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 #9232 onto the 15.6 branch. This fixes them.
We also needed to add some logic from #9399

**why make this change?:**
To keep tests passing and get this change working.

**test plan:**
`yarn test`

**issue:**
#9398

* Move component base classes into a single file (#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:**
#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`
flarnie added a commit to flarnie/react that referenced this pull request Jun 7, 2017
* 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`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants