Uh oh!
There was an error while loading. Please reload this page.
Remove createClass - #9232
Conversation
| Object.defineProperty(React, 'createClass', { | ||
| get: function() { | ||
| warning( | ||
| warnedForCreateClass, |
There was a problem hiding this comment.
What do you think about waiting for first call and including the class displayName in the message?
There was a problem hiding this comment.
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.
nhunzaker
commented
Mar 22, 2017
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! |
bvaughn
left a comment
There was a problem hiding this comment.
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.
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.
Isn't the check there to see if you can use Object.defineProperty though?
acdlite
commented
Mar 22, 2017
I'll wait to merge this until we've updated the |
sophiebits
commented
Mar 24, 2017
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. |
acdlite
commented
Mar 24, 2017
@spicyj What was the reason for removing them in the first place? |
acdlite
commented
Mar 24, 2017
@spicyj On that point, we should obscure the |
sophiebits
commented
Mar 24, 2017
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. |
acdlite
commented
Mar 24, 2017
@spicyj I'm cool with killing |
sophiebits
commented
Mar 24, 2017
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. |
acdlite
commented
Mar 24, 2017
@spicyj I figured we would keep them around for a few more releases and then when it breaks for |
sophiebits
commented
Mar 24, 2017
I meant rewrite them without using internals: for replaceState, setting all existing keys to |
bvaughn
commented
Mar 24, 2017
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. |
bvaughn
commented
Mar 24, 2017
Yeah, I didn't think that case is important to support. |
sophiebits
commented
Mar 24, 2017
I am happier breaking that now then forgetting about it forever. |
acdlite
commented
Mar 24, 2017
If we do this, I think we should warn... at least in |
bvaughn
commented
Mar 24, 2017
What if we only warned the first time |
acdlite
commented
Mar 24, 2017
@bvaughn Are you concerned about too many warnings? |
bvaughn
commented
Mar 24, 2017
Not really. If we only warn...
I think we're unlikely to bother many people. |
gaearon
commented
Mar 24, 2017
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
|
acdlite
commented
Mar 24, 2017
@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 |
gaearon
commented
Mar 24, 2017
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. |
acdlite
commented
Mar 24, 2017
I'm going to warn for |
sophiebits
commented
Mar 24, 2017
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. |
acdlite
commented
Mar 24, 2017
@spicyj Oh maybe we do, wasn't aware! |
acdlite
commented
Mar 24, 2017
Turns out we have a warning for props but not state |
acdlite
commented
Mar 27, 2017
Update: The Immutable JS case (preserving the prototype when calling |
8795b7b to
8708a07Comparebvaughn
commented
Mar 27, 2017
Corresponding update to |
The `React.createClass` is going to be deprecated soon and will be removed in React v16. react/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.
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.
**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 react#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:** react#9398
**what is the change?:** A couple of bugs and holes were introduced when cherry-picking react#9232 onto the 15.6 branch. This fixes them. We also needed to add some logic from react#9399 **why make this change?:** To keep tests passing and get this change working. **test plan:** `yarn test` **issue:** react#9398
**what is the change?:** A couple of bugs and holes were introduced when cherry-picking react#9232 onto the 15.6 branch. This fixes them. We also needed to add some logic from react#9399 **why make this change?:** To keep tests passing and get this change working. **test plan:** `yarn test` **issue:** react#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 react#9232 onto the 15.6 branch. This fixes them. We also needed to add some logic from react#9399 **why make this change?:** To keep tests passing and get this change working. **test plan:** `yarn test` **issue:** react#9398 * Move component base classes into a single file (react#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:** react#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. react/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.
The `React.createClass` is going to be deprecated soon and will be removed in React v16. react/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
replaceStateorisMounteduseupdater.enqueueReplaceStateandupdater.isMountedinstead.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.