-
Notifications
You must be signed in to change notification settings - Fork 24.5k
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
Add ES6 Symbol polyfill for compatibility with iOS 8 and Android #5294
Conversation
By analyzing the blame information on this pull request, we identified @cpojer, @martinbigio and @sahrens to be potential reviewers. |
Thanks a lot for the fix @skevy! @davidaurelio How do we merge PRs that add dependencies now that we have the new infra for storing node_modules internally? For context, we have a custom way to fetch node_modules at fb because React Native is used in the main fb apps and there are engineers working on those apps who don't deal with JS, npm, etc. (we also don't want CI servers to run 'npm install' because it takes forever :)). We used to check node_modules into the Mercurial repo but maintaining that proved to be a pain so we have a new system to do that. |
@mkonicek I guess for now we have to have these imported by a FB employee and do the necessary things. We could enhance the bot to a) require that or b) do the necessary things itself. |
@@ -126,6 +126,10 @@ function setUpAlert() { | |||
} | |||
} | |||
|
|||
function setUpSymbol() { | |||
GLOBAL.Symbol = require('es6-symbol'); |
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.
I don’t think we want to overwrite native Symbol
if present.
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.
i.e. use require('es6-symbol/implement');
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.
https://github.com/medikoo/es6-symbol/blob/master/index.js#L3
Am I reading that wrong? It seems like it's checking for native, global Symbol
before it polyfills.
Or would you rather have that check in our code?
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.
I’m sorry, I misunderstood their documentation.
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.
@davidaurelio np :) If you'd rather me move the check into RN so it's more clear, I'm happy to do that!
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.
no, it’s good the way it is. @mkonicek will take care of merging
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.
Thanks gentlemen!
@facebook-github-bot import |
Thanks for importing. If you are an FB employee go to https://our.intern.facebook.com/intern/opensource/github/pull_request/1107166042641372/int_phab to review. |
I just did Here are all the files: http://pastebin.com/wyePxHtd cc @vjeux, @davidaurelio |
Could we use core-js instead of es6-symbol, since that's what Babel uses (or used to use...) and should get deduped with Babel? |
What about using |
@mkonicek sorry I didn't see this. I'll take a look. I'm sure we can figure out a different solution. We actually do already have Babel-polyfill in deps (not actually sure why)...I was just hesitant of using that as it adds a lot of code to people's bundles and doesn't really add that much (since we polyfill a bunch anyway). I'm AFK at the moment, but my intuition tells me that either we can vendor a symbol polyfill or try core-JS... |
Honestly, I wouldn't be surprised if the deps that es6-symbol added are deps we already have somewhere in the tree...but that's not how npm works. :-( |
@skevy Yes I was just worried when I saw this was adding files like I have little context, just read the Symbol docs last week. If you guys more familiar with JS are happy with merging this go ahead. I was just asking whether adding all this code was worth it, and you're right all of it might already be in the tree :( It's frustrating to see the |
@mkonicek totally agreed. Hold off on merging this everyone - I'm gonna just vendorize this polyfill -- absolutely no reason to add a huge dep. |
@mkonicek I am going to do this right now though, so hopefully we can still get this into RN 0.18...would be a good fix as this causes a problem on < iOS 9 and Android (some or all...not sure). |
OK so actually, two comments on this:
|
The size of the bundle is more important than the size of node_modules here. npm uses gzip and npm 3 is not bandwidth-constrained, and 3xxMB is a fraction of a percent of modern HDD space. So whatever polyfill gives us some combination of compact and clean code is actually my preference, whether that's core-js or something else. |
I'm talking to @vjeux about this...will report back. |
Here's the plan:
It just replaces
|
Nice! I've released 0.18.0. Can anyone release 0.18.1 with the single extra commit? Since it's a JS-only change, it's just |
ping @bestander :) |
@DmitrySoshnikov what would be the specific point of defining |
@skevy, I meant in case if you don't wanna use loose mode. Otherwise it should be fine (we don't have |
@DmitrySoshnikov great. We'll go with using loose mode + documenting what we do and don't support. @vjeux you good with this plan? |
Works for me, Dmitry is the pro here :p |
Ok - I'm going to close this then in favor of adding loose mode in #5214 and then I'll open a new PR with doc changes. |
Summary: Turns out, even after discussion that was had in #5294 (comment), we really do need this transform. I've just included it in the preset...let me know if you all would rather publish to npm. The actual reason why this is necessary is because in the latest sync from FB, fbjs was updated to use the `Symbol.iterator` express in it's isEmpty function: facebook/fbjs@064a484 We use this in RN in the ListView...and this change (once #5084 is merged) will cause ListView to break on older JSC context's. This resolves that, and is probably something we should have had all along. Closes #5824 Reviewed By: svcscm Differential Revision: D2913315 Pulled By: vjeux fb-gh-sync-id: abaf484a9431b3111e8118d01db8d2c0d2dd73ca shipit-source-id: abaf484a9431b3111e8118d01db8d2c0d2dd73ca
Summary: Turns out, even after discussion that was had in #5294 (comment), we really do need this transform. I've just included it in the preset...let me know if you all would rather publish to npm. The actual reason why this is necessary is because in the latest sync from FB, fbjs was updated to use the `Symbol.iterator` express in it's isEmpty function: facebook/fbjs@064a484 We use this in RN in the ListView...and this change (once #5084 is merged) will cause ListView to break on older JSC context's. This resolves that, and is probably something we should have had all along. Closes #5824 Reviewed By: svcscm Differential Revision: D2913315 Pulled By: vjeux fb-gh-sync-id: abaf484a9431b3111e8118d01db8d2c0d2dd73ca shipit-source-id: abaf484a9431b3111e8118d01db8d2c0d2dd73ca
👍 |
I upgraded to RN 0.20 and I'm now getting a different error. My code looks like this:
and it appears to transpile into this:
which produces this error:
Indeed, my array doesn't contain functions, so I don't understand how this transpiled code is supposed to work. Does anyone know what's going on? Thanks. |
@lrettig in JS environments that support I'm not sure why that's not working for you...are you using any custom babelrc or any type of custom config? |
There was indeed some junk in my .babelrc that must have caused this. I removed it, and it started working. Thanks! |
So the reason, for what it's worth, that it wasn't working...is because your code was not being transpiled into the "for...of" loose mode code. This is important for non-Symbol supporting JS platforms. |
I suspect the culprit was this entry in my .babelrc "plugins": On Mon, Feb 29, 2016 at 1:36 AM, Adam Miskiewicz [email protected]
|
Note that we have a preset now...called "babel-preset-react-native" that you can install and use in your babelrc, rather than copying the RN config or using the This ensures that you're using all the proper transforms that RN requires. |
related to this by any chance? gaearon/react-proxy#50 |
Summary: Turns out, even after discussion that was had in facebook#5294 (comment), we really do need this transform. I've just included it in the preset...let me know if you all would rather publish to npm. The actual reason why this is necessary is because in the latest sync from FB, fbjs was updated to use the `Symbol.iterator` express in it's isEmpty function: facebook/fbjs@064a484 We use this in RN in the ListView...and this change (once facebook#5084 is merged) will cause ListView to break on older JSC context's. This resolves that, and is probably something we should have had all along. Closes facebook#5824 Reviewed By: svcscm Differential Revision: D2913315 Pulled By: vjeux fb-gh-sync-id: abaf484a9431b3111e8118d01db8d2c0d2dd73ca shipit-source-id: abaf484a9431b3111e8118d01db8d2c0d2dd73ca
This missing polyfill causes this weird behavior with immutable immutable-js/immutable-js#1474 Thought I'd leave it here for reference |
Fixes #4676