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

Remove object-assign polyfill #10280

Closed
wants to merge 1 commit into from
Closed

Conversation

gaearon
Copy link
Collaborator

@gaearon gaearon commented Jul 26, 2017

Since we already depend on Map and Set I figured we might as well ask users to polyfill Object.assign if they need to.

In browsers, it's still not supported everywhere (e.g. IE 11 doesn’t but Edge does). There is a precedent: Relay Modern, Preact, Inferno don’t ship with it. Many Redux apps use Object.assign so users resort to polyfilling it anyway.

In Node, there was an issue with bad Object.assign implementation in some Node version that caused different attribute order. But Fiber is resilient to that so it wouldn’t be a problem anyway.

screen shot 2017-07-26 at 12 53 07 pm

Test plan: packaging fixtures work. For internal FB bundles, we didn’t use it in the first place (because we had our own polyfill).

screen shot 2017-07-26 at 12 54 49 pm

@jquense
Copy link
Contributor

jquense commented Jul 26, 2017

I potential difference in this case from others is that Babel will include its _extends polyfill anyway, it seems like a waste to not use it for this case? It may not be a perfect polyfill but I'd be surprised if that matter here

@jquense
Copy link
Contributor

jquense commented Jul 26, 2017

Talking about this specifically, as a replacement for the extra code. https://babeljs.io/docs/plugins/transform-object-assign/

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 26, 2017

Babel will include its _extends polyfill anyway, it seems like a waste to not use it for this case?

Why will Babel include it? I’m not sure I’m following. Do you mean we already have it in our builds? I would expect that not but maybe I’m wrong.

@jquense
Copy link
Contributor

jquense commented Jul 26, 2017

sorry I should re-phrase that :P, its an internal help babel inlines for a few general transforms, You can see it in react-dom@16 doing a find for _extends: https://unpkg.com/[email protected]/umd/react-dom.development.js

Since it's already there, you can use the linked transform to change Object.Assign references to use that instead. It doesn't actually polyfill anything, it works like the plugin you are removing but uses the core babel helper.

@jquense
Copy link
Contributor

jquense commented Jul 26, 2017

The funny thing is that it looks like the Babel transform is deferring to this polyfill lol. It is normally Object.assign || inlineassignhelper, eg. babel inlines the helper then the react babel plugin is replacing it's inlined reference to Object.assign with the object-assign package

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 26, 2017

Seems like it's used in just one place, we can probably remove that.

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 26, 2017

Or better yet, configure Babel to always use real Object.assign for spread instead of the helper.

@jquense
Copy link
Contributor

jquense commented Jul 26, 2017

sure, easy enough maybe to avoid it, but it seems like an easy win for folks to not have to install another package, add another line to their entry (before React) etc.

On an unrelated note is there an issue tracking warning for things that need to polyfilled? I ran into this trying to test ie9 on the fixture app the other day. I got a hard error for Set and Map missing instead of the more normal "Hey react requires this, here is where you can install a polyfill"

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 26, 2017

The plan is to document new required baseline (just like it was the case before ES5 became supported everywhere).

We will probably require Map, Set, requestAnimationFrame (on the client), and Object.assign. But there is no final consensus yet.

Similar to https://facebook.github.io/relay/docs/relay-modern.html#javascript-environment-requirements.

@aweary
Copy link
Contributor

aweary commented Jul 26, 2017

We have an invariant check for requestAnimationFrame, can we do the same here, and for the other required primitives?

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 26, 2017

Yeah, we could. Do you want to send a PR?

@Daniel15
Copy link
Member

In Node, there was an issue with bad Object.assign implementation in some Node version that caused different attribute order.

No code should be relying on the exact order of object properties though, so this should be safe.

@gaearon
Copy link
Collaborator Author

gaearon commented Jul 27, 2017

Our own code was—because we used to compare checksums for markup generated on the server and on the client. But we don’t anymore.

@bvaughn bvaughn mentioned this pull request Aug 1, 2017
@sebmarkbage
Copy link
Collaborator

sebmarkbage commented Aug 1, 2017

For inline styles hydration warning we still rely on enumeration order I think. Because we generate a compatible string that we compare against the attribute.

@gaearon
Copy link
Collaborator Author

gaearon commented Aug 1, 2017

Ah, I see. Another downside of this is it makes IE11 incompatible which otherwise meets our requirements for minimal target. Let's wait with this until 17.

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.

6 participants