-
Notifications
You must be signed in to change notification settings - Fork 24.3k
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
Change Object.assign polyfill to NOT walk entire prototype chain and to NOT force ideologies #16511
Comments
Created a PR for this issue: #16512 |
@th317erd thanks for the PR. i suggest changing the title to something more meaningful. |
Kind reminder that there is a Code of Conduct in effect. @th317erd, consider this a first warning, and let's make sure any future comments are friendlier and respectful to contributors. |
@hramos I understand that, and appreciate the reminder. Now if you apply the code of conduct to the reason I was upset in the first place you will see the Facebook team violated it in multiple ways by forcing ideologies:
Again, I will try to have better manners in the future, and I appreciate you listening, and I appreciate your patience with me. I tend to get upset when someone tries to force me into a practice or ideology. Thanks! |
Please note that I want to help make this satisfy your concerns. The PR is quite difficult to review and merge confidently, this is true polyfills in general. The following explains why. I have no context on the initial intent of this code, but I assume that the people who wrote it were smart engineers with more context on the situations it needs to support than I do currently. The fact that there is a specific warning about the
It feels like it would be fairly bad form for us to ignore these warnings without better understanding the situations they were meant to solve. Unfortunately, these warnings were not codeified via tests. Also unfortunately, I couldn't trace the history of this file back to where it was added or modified to be able to see if the original authors remember anything about the reasons. The only people I could find related to that history were @mjesun and @davidaurelio. Perhaps they have some context. In the mean time, while we are trying to get more context before figuring out how to move forward with those changes, I'd be happy to accept a PR that just contains the additional existence check that you added.
This check exists on the other polyfills and I can't imagine why we'd want to override an existing FWIW, I also have a hard time fully understanding the problems you are trying to address. From you initial post it seems like the main complaint you have is:
When trying to deconstruct that complaint and understand the specifics, I can understand the first half being performance related. For "force ideologies", I'm not exactly sure what you mean by that. Is that specifically about us overriding existing |
@TheSavior Thanks for the feedback. To answer your last question: My complain is 1) Walking the prototype chain while merging objects is slow, and not to standard, 2) Because of 1 there are many instances of code that will break when there ARE enumerable properties in the prototype chain (i.e. inheriting from While Does that help clear things up? Again, thanks for your time and effort on this. I would certainly be interested on the mentality behind the code in the first place. Let me know what you find out. |
Since there are very specific uses where the existing code would cause it to break but that code should work, I think the best way for us to understand that and ensure it continues to work would be for you to actually write those cases down as unit tests. It would be good to reproduce those cases in our test suite and ensure that updating the polyfill will solve them. Ideally this would have occurred with the initial changes to the polyfill and if it was we wouldn't be in this situation now. Let's keep our future RN engineers from running into the same problems as us down the road. Regarding the |
@TheSavior "Also, since all of our other polyfills appear to have that check already, it doesn't seem like those concerns would be unique to this file. For that reason, it seems reasonable to add that separately, earlier." I agree it certainly makes sense to add that change to the polyfill ( I will write unit tests when I have some free time, which might not be for a few days |
So @TheSavior , I have been thinking about this a lot (haven't had time to come back to it yet to write those tests). I doubt this will break anything. It is functionally identical (pulling only the top-level object keys). The only difference is that, unlike the current polyfill code, it won't check the rest of the prototype chain. So any code that is currently running (not throwing an error due to that check) should behave exactly the same. Since this is throwing an error for everything... it should be fine? The only concern I can think of is if someone did something stu--- I mean "funky" elsewhere that REQUIRED this check not to break, and without the code throwing an exception here maybe it will have issues elsewhere because of enumerable keys in the prototype chain? Anyhow, just a thought... I guess we could always search the code base for any |
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Maybe the issue has been fixed in a recent release, or perhaps it is not affecting a lot of people. If you think this issue should definitely remain open, please let us know why. Thank you for your contributions. |
Is this a bug report?
Yes
Have you read the Contributing Guidelines?
Yes
Environment
Environment:
OS: Linux 4.10.0-35-generic #39-Ubuntu SMP Wed Sep 13 07:46:59 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Node: 8.1.3
npm: 5.3.0
Packages: (wanted => installed)
react-native: 0.49.3 => 0.49.3
react: 16.0.0-beta.5 => 16.0.0-beta.5
Target Platform: Android (7)
Steps to Reproduce
(Write your steps here:)
var a = { test: 'derp' }
a
as the prototypevar b = Object.create(a)
b
to a new objectvar c = Object.assign({}, b)
Expected Behavior
react-native shouldn't slowly walk the entire prototype chain or force ideologies
Actual Behavior
react-native DOES slowly walk the entire prototype chain AND force ideologies
Reproducible Demo
https://github.com/facebook/react-native/blob/master/Libraries/polyfills/Object.es6.js
Your Polyfill for Object.assign (Object.es6.js) is completely backwards, slow, and forcing an ideology. You are DELIBERATELY walking and copying the entire prototype chain, which is slow, and often not desired. The SUPER INSANE part? You are telling me how to live my life, and throwing an exception if there IS an enumerable property in the prototype chain. Forcing people to do things YOUR way is the wrong way. Please update the polyfill to 1) NOT walk the entire chain, 2) NOT tell me how to code.
By the way, I ran into this simply inheriting from EventEmitter, which is SUPER COMMON by the way.
I am upset that Facebook has written controlling polyfills forcing ideologies and telling me how to live my life. Please stay off my lawn, stop telling me how to code, and stop doing things the slow way just to tell other people how to do things
The text was updated successfully, but these errors were encountered: