-
Notifications
You must be signed in to change notification settings - Fork 47k
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
Use object-assign instead of our own dated "polyfill" #6376
Conversation
You probably know which option I like 😄 .
|
Just out of curiosity, why use |
@aweary I'm aware of that. My suggestion is to use the babel version since that means eventually you'll be able to turn the transform off without having to rip out require references all over the codebase. |
Wouldn't it make more sense to have this redirect live in fbjs? E.g. a forwarding module. That's the place where we swap out FB specific polyfills for community ones. |
@zpao updated the pull request. |
Why are we picking My only concern for this is perf. We know that we've intentionally overridden this in RN in the past because it is too slow. How do we override this internally? |
Babel desugars spread operator to this helper: "use strict";
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; However if you import |
I picked object-assign because it's stable and apart from the Symbol support, virtually identical to what we have now. Compare https://github.com/sindresorhus/object-assign/blob/master/index.js to https://github.com/facebook/react/blob/05b05c4c81154b6e653a10479dd77a569d2b52f7/src/shared/stubs/Object.assign.js In RN if perf is a concern then they can set Object.assign before loading any other modules and they'll be better off anyway (will catch the user code too). Since this module actually uses Object.assign first instead of always using a custom method that means RN only has 1 thing to override. on www we would have
This is what we do already for As for fbjs… in theory sure. But React is pretty much the only thing internally using this Object.assign module. Everything else uses Object.assign or spread directly. I chose not to use the babel transform / runtime since I didn't want to make another direct dependency on core-js which isn't the smallest dep. And inlining |
@zpao updated the pull request. |
What is the plan going forward with regard to requiring the users to polyfill ES6 features themselves? Is there a benchmark that should be met for React to change the base requirement from ES5 to ES6? |
There isn't a solid plan, we've mostly taken them on a case by case basis. We've inlined in a couple places (eg ES5 was easy to make the call and just tell people to bring their own. Personally I mostly feel the same about ES6, with some careful consideration about using things that can't be polyfilled. I don't know what the benchmark is to get everybody to agree with me though :) Historically Node made that harder to really say but with the recent upgrade rate it's much more doable. Polyfilling a Node environment is still pretty gross though and I don't think I could comfortably argue that everybody doing server rendering must |
Might I suggest my comment #6372 (comment) to be a possible solution going forward? |
@zpao updated the pull request. |
FYI: I'm cleaning up other callers internally and in RN (#6376) so I think I might change this slightly so that we are using the |
Probably facebook/react-native#6766. |
Summary:I'm [getting rid of it from React](facebook/react#6376) and so I'd like to get this in before we accidentally break RN. There are a bunch of other uses of Object.assign directly so this should be perfectly safe. Closes #6766 Differential Revision: D3128135 Pulled By: vjeux fb-gh-sync-id: 675913ba457abcd8c194facb9ff58255c9dceda5 fbshipit-source-id: 675913ba457abcd8c194facb9ff58255c9dceda5
@zpao updated the pull request. |
Took it one step further and replaced all uses of our own assign with Object.assign directly. I wrote a Babel plugin (based on the idea of http://babeljs.io/docs/plugins/transform-object-assign/ but inserting requires instead of the _extends helper for less code and an actual Object.assign polyfill). I could have used // before
var assign = require('Object.assign');
assign(...);
// after
Object.assign(...);
// after transform
var _assign = require('object-assign');
_assign(...) |
@sebmarkbage accepted verbally the other day so just updating the label to match that. |
@zpao updated the pull request. |
I don't know if this is the right place to say it but in the future it would be nice to avoid code removals between the last RC and the final version. With RC1 and 2 everything was working perfectly fine but with the final version some (pretty popular as you can see above) React components broke because they relied on a react polyfill that did not exist anymore. IMHO it would have deserved a RC3 to give time for the maintainers to adapt instead of breaking the code without previous notice. I know it is hard to imagine all the possible outcomes but removing an internal function might always have negative consequences that should be prevented before the launch. |
@gaearon could we export |
Oh, I was referring to removing While
|
We won't be re-adding that module. None of the We're reverting the
You're right, we should have done an RC3. |
In a way... Causing havoc is sometimes a good thing. It helps enforce expectations. We should avoid if possible though.
|
Summary:I'm [getting rid of it from React](facebook/react#6376) and so I'd like to get this in before we accidentally break RN. There are a bunch of other uses of Object.assign directly so this should be perfectly safe. Closes facebook#6766 Differential Revision: D3128135 Pulled By: vjeux fb-gh-sync-id: 675913ba457abcd8c194facb9ff58255c9dceda5 fbshipit-source-id: 675913ba457abcd8c194facb9ff58255c9dceda5
Not 100% sure if we should do this and add to the list of "where does this come from" modules. Simply rewriting and requiring the defacto polyfill instead of our own. This will require a few small changes internally.
A couple alternatives:
require('Object.assign')
torequire('object-assign')
. Same amount of work, but potentially clearer that this is the npm module and now a providesModule. This will play nicely into Get rid of providesModule #6336 when that happens.Net result for browser packages is the same for all of these - we end up with object-assign packages. The only real difference would be in the npm package and adding another dependency.
Fixes #6372