-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Remove createClass #9232
Remove createClass #9232
Conversation
Object.defineProperty(React, 'createClass', { | ||
get: function() { | ||
warning( | ||
warnedForCreateClass, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about waiting for first call and including the class displayName in the message?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can do that in 15.5 (I have a separate branch that I haven't pushed to yet) but in 16 React.createClass
is undefined. We could use a void function and warn in there but that would lead to confusing errors in prod.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh okay.
Very cool! @aweary I'll make sure this doesn't conflict with our Dom fixtures. |
In case anyone else is curious, here's the relevant
So the gzipped and minified version of react (the size most people should be shipping) is a whole 1kb smaller with this change. 🎉 For more context, here are the full sizes from master:
And the size from this PR:
So that 1kb drop in the minified/gzipped react represents a 17% drop in the overall size. This is not insignificant! :party_parrot: Great work @acdlite 👏 Edit: @aickin pointed out that most people should probably care about the react.js and react.dom.js combined size. Taking that into account, this is more like a 2.3% drop. Still super significant! Yay! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks fantastic! So exciting to see all that deleted code and the file size reductions Kent mentions above. 😁
return mixin; | ||
}; | ||
|
||
if (canDefineProperty) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Curious why not move canDefineProperty
and warning
require statements into this __DEV__
block so you can get rid of this check? They're only used here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the check there to see if you can use Object.defineProperty
though?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
😆 Yes, ignore me.
I'll wait to merge this until we've updated the |
Can we implement replaceState and isMounted in user land then kill them on the updater? I don't want to have to maintain those as public API. |
@spicyj What was the reason for removing them in the first place? |
@spicyj On that point, we should obscure the |
replaceState is noncompositional and makes it harder to add new state properties to a component; isMounted is often better done as a subscription that gets cancelled. |
@spicyj I'm cool with killing |
My point is, replaceState and isMounted are only supported on createClass so we should have the createClass implementation handle them internally rather than keeping logic forever in React proper to support them. |
@spicyj I figured we would keep them around for a few more releases and then when it breaks for |
I meant rewrite them without using internals: for replaceState, setting all existing keys to |
Wouldn't this be as simple as setting an instance prop in |
I don't think it's exactly the same. What if you call But maybe this is "close enough" to not matter. Not sure. |
Yeah, I didn't think that case is important to support. |
I am happier breaking that now then forgetting about it forever. |
If we do this, I think we should warn... at least in |
What if we only warned the first time |
@bvaughn Are you concerned about too many warnings? |
Not really. If we only warn...
I think we're unlikely to bother many people. |
Can we realistically break anything with this slight change in behavior? Are we making |
I think it's unlikely. If you're doing DOM cleanup (eg removing event listeners) in
|
@bvaughn No I meant to ask, why not warn on every usage? It's an anti-pattern, anyway. Then the user is directed to either find a better solution or implement a |
If it's in a library code then warning on every usage will spam the console unactionably. I think people had enough bad experience with the unknown DOM property warning that we should be very careful with adding repeated warnings. |
So here's what I'll do: Implement |
I'm going to warn for |
I thought we had a warning for that already maybe? As long as you mean just "warn on every non-plain-object" I guess that's okay. |
@spicyj Oh maybe we do, wasn't aware! |
Turns out we have a warning for props but not state |
Update: The Immutable JS case (preserving the prototype when calling |
8795b7b
to
8708a07
Compare
Corresponding update to |
The `React.createClass` is going to be deprecated soon and will be removed in React v16. facebook/react#9232 This patch changes the component to a class extended from `React.Component`. It does it manually by assigning to the prototype, to avoid introducing a build step.
8708a07
to
ed00197
Compare
Remove createClass from isomorphic package
instead of createClass
Tests that rely on replaceState or isMounted use updater.enqueueReplaceState and updater.isMounted instead.
Should still be undefined.
This snuck in after rebasing
These are mostly copied from the old ReactClass-test module.
ed00197
to
957fbc9
Compare
**what is the change?:** NOTE: There are still bugs here, we will need at least a few more fixes. A couple of bugs and holes were introduced when cherry-picking facebook#9232 onto the 15.6 branch. This fixes them. **why make this change?:** To keep tests passing and get this change working. **test plan:** `yarn test` **issue:** facebook#9398
**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
**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
* 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`
* 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`
The `React.createClass` is going to be deprecated soon and will be removed in React v16. facebook/react#9232 This patch changes the component to a class extended from `React.Component`. It does it manually by assigning to the prototype, to avoid introducing a build step.
Tests that rely on
replaceState
orisMounted
useupdater.enqueueReplaceState
andupdater.isMounted
instead.Won't be released until 16. In 15.5 we'll deprecate and point users to an external module,
react-create-class
. After than we'll continue to warn but it will no longer be accessible via the main React package.