-
-
Notifications
You must be signed in to change notification settings - Fork 408
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
RFC: Deprecate array prototype extensions #848
RFC: Deprecate array prototype extensions #848
Conversation
Co-authored-by: Chris Krycho <[email protected]>
Co-authored-by: Chris Krycho <[email protected]>
Co-authored-by: Chris Krycho <[email protected]>
Co-authored-by: Chris Krycho <[email protected]>
Please enter the commit message for your changes. Lines starting
Co-authored-by: Chris Krycho <[email protected]>
Thanks so much for doing this work! I will bring it to the Framework meeting this week for initial discussion. 💙 |
Should we also display a deprecation warning at build time when |
That's a good point! |
- Do nothing. | ||
|
||
## Unresolved questions | ||
- Current lint rule [ember/no-array-prototype-extensions](https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/no-array-prototype-extensions.md) gives a lot of false positives giving the limitation of static analysis. |
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.
these false positives will be greatly reduced soon because in ember-data 4.8 usages of these has already been deprecated. This means remaining usage is from A()
which I would hope this RFC would consider simultaneously deprecating or various other ArrayProxy
implementations which are far less common.
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.
Agreed! One of the things I plan to discuss at Friday's Framework Core meeting is exactly whether we should deprecate @ember/array
entirely and/or at least extracting it and move it out to a separate package which is not installed by default.
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.
Sure, but the reason I mention A
is that A
mutates array instances when prototype extensions are turned off. If we're going to rip off the bandaide it seems better to rip it fully off vs allowing people to just call A
on everything to get back to the same state.
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.
Another sets of false positives are self-defined class functions, for exampleinvoke
, clear
are pretty common method names.
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.
@runspired yeah, I spent literally my whole day today dealing specifically with the horror caused by the NativeArray
shenanigans as relates to types. If it were my preference alone, we'd deprecate it and cut a special v5.0 tomorrow just to get rid of A()
. 😂
@smilland yeah, unfortunately that kind of thing is basically impossible to avoid 100% without full TS coverage (which we obviously can't require people to have!).
I would like to suggest going even further than this and considering using only a single deprecation message for having The reason I'd suggest this is that it's much easier to implement and I think it would actually give clearer feedback to developers. The instructions for clearing the deprecation would be to flip the flag and fix what breaks. The stack traces you'll get from the lack of prototype extensions will point at precisely the right place to make the fixes. |
We had three notes coming out of today's Framework Core discussion of this RFC.
Once (1) and (2) here are done, I think we have a clear path to moving this forward! Thanks again! |
I know it feels out of scope but I want to reiterate that I feel we should more broadly deprecate The reason this concerns me so much is two-fold.
I think the big problems are that it creates the potential for race-conditions in code that is otherwise not-aware of this instance conversion occurring, as well as it subtly changes the behavior of array-like in an extremely significant way: all array-like primitives will have to be careful to guard against their methods being clobbered as they are now below in the chain instead of above in the super chain. What's more, it takes something that folks don't understand today (namely that I wonder if we could get away with |
I also think that regardless of whether we add deprecation of or alteration of |
@runspired that's an important call-out, which I'll make sure we address explicitly before putting this into FCP (hopefully in two weeks—I’m out next week). I think we should probably tackle that in the associated RFC instead of this one—we agreed already today that both need to go, but probably separately. |
Should we also include something about the |
The biggest downside of this change for me is the loss of the I also use these functions extensively during interactive debugging, where the fact they are array prototype extensions is a huge boost, as it is near impossible to import an arbitrary function from a third-party library in the browser's JS console. I suppose I could resort to native Array methods, but then I have to write out a lambda function every time, which is tedious and I'm sure will leave me cursing the loss of these beloved convenience functions. Are there any thoughts on how best to cope with this loss of productivity? EDIT: I'm genuinely looking for suggestions here -- if my app imports a Lodash function, am I able to access that same function directly from JavaScript console as easily? Do I just need to export my own custom object containing the functions to the global scope? If that's the answer, then so be it -- I mainly wanted to recognize the convenience value here and solicit input on the best way to retain that convenience after this change. |
Forgot a big gotcha in removing these as extensions and using utilities, optional chaining doesn't do the job anymore. If you currently have |
Thanks for your comments! We'll want to make sure those details get captured as we post about these deprecations. That said, I think the RFC addresses the trade offs clearly, and as a result there is zero interest in keeping around any of them as prototype extensions... They are, presently anyway, available separately as utilities importable from the We will make sure to talk through these points once more at Framework Core on Friday, though! This is what FCP is for! |
The implementation of #846 is fully realized and in #745 and the ember-data 4.7 release. If there's a bug let's fix it :)
This should not at all be required in 4.7
Would love an example / to hear more about this. I'm not sure what you're pointing out. Pre EmberData 4.7 using some native array APIs could lead you to getting the backing content (InternalModel/Identifier depending on version) but starting in 4.7 regardless of native array API used you should get the record instance. |
To echo what @chriskrycho is saying here, mutating the Array Prototype has historically (and I believe still?) caused arrays to opt into a de-opted slow state. There's a large number of such pitfalls around array APIs, even to the extent that the single use once of an array API on an instance of an array in a specific way can cause all arrays to not only de-opt but for that de-opt to persist across browser sessions. Ending our mutation of array prototypes and array instances entirely is very important. |
Thank you @jrjohnson for sharing the deprecation experiences and gotchas. Contributions to the deprecation guide are heartily welcomed and appreciated as well ❤️ . ember-learn/deprecation-app#1192 |
Hi @ef4 @chriskrycho , this RFC has been in FCP for over a week now. Let me know if there is anything else pending and what's the next step. Thanks! |
Nope, all good on your end! We just haven't had a chance to discuss it again: a lot of folks were out last week for EmberFest. It's at the top of the agenda for this week's meeting! |
We discussed this again at Framework Core today and are merging it (…once we get the lints fixed)! Thanks again, @smilland! |
@chriskrycho That's awesome! Fixed lint. Thank you for all the guidance, support, and discussions. ❤️ ❤️ |
Merged. Thanks again! Excited to see it implemented. |
Sweet! Already opened ember-cli/ember-cli#10017 for Ember CLI. |
@smilland hi, the "rendered text" link in the original post leads to a 404. Is there a copy anywhere else? thanks, Edit: found a copy here: https://github.com/smilland/rfcs/blob/734fa12241674cca56ea7a3b30b6eb027ebde752/text/0848-deprecate-array-prototype-extensions.md |
This will need to grapple with some of the issues in #864 as well. When array prototype extensions are disabled, Ember.A gains the behavior of mutating its argument to add those tensions back in. This can have weird and wonderful effects at a distance that are hard to deal with. |
Advance RFC #848 `"Deprecate array prototype extensions"` to Stage Ready for Release
Advance RFC #848 `"Deprecate array prototype extensions"` to Stage Released
Advance RFC #848 `"Deprecate array prototype extensions"` to Stage Recommended
Rendered text