Skip to content

Ember.A should not modify underlying array - #20245

Closed
wagenet wants to merge 4 commits into
emberjs:mainfrom
wagenet:ember-a-improvements
Closed

Ember.A should not modify underlying array#20245
wagenet wants to merge 4 commits into
emberjs:mainfrom
wagenet:ember-a-improvements

Conversation

@wagenet

@wagenet wagenet commented Oct 31, 2022

Copy link
Copy Markdown
Member

Resolves #20219

@wagenet
wagenet marked this pull request as ready for review October 31, 2022 22:38

const emberArrayLastObject = nonEnumerableComputed(function () {
return objectAt(this, this.length - 1);
}).readOnly();

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love how we're assigning them to variables here, but I can't find any other good way to get a reference to their CPs.

let proxy = new Proxy(arr, {
get(target, prop /*, _receiver */) {
// These nonEnumerableComputed properties need special handling
if (prop === '[]') {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd have something more generic, but we aren't going to be adding stuff to EmberArray going forwards so this should be fine.

@chriskrycho

chriskrycho commented Nov 1, 2022

Copy link
Copy Markdown
Contributor

@wagenet note that "Extend Prototypes" is failing on CI.

@wagenet
wagenet force-pushed the ember-a-improvements branch from 7dd16a6 to 7aa79fa Compare November 1, 2022 15:11

@chriskrycho chriskrycho left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems reasonable to me, but I'd still really like it if someone who's more familiar with this could give it some 👀 as well. @rwjblue do you have 10 minutes (tops) to look at it?

@wagenet

wagenet commented Nov 22, 2022

Copy link
Copy Markdown
Member Author

I think I'd like to put this behind a flag. I think (hope) it won't cause issues for people, but who knows what people are actually doing and whether they're relying on the mutating behavior.

@wagenet
wagenet force-pushed the ember-a-improvements branch from 7aa79fa to 0b2ab6f Compare November 23, 2022 15:55
@wagenet
wagenet force-pushed the ember-a-improvements branch 2 times, most recently from 00ccece to 582831f Compare January 3, 2023 23:16
@jrjohnson

Copy link
Copy Markdown

I agree that it should go behind a flag. Because many addons call A() on basically everything there are probably lots of components in production today that pass something through an addon helper such as {{map-by "id" this.posts}} and then rely on some prototype pollution elsewhere in a getter or action without realizing that the template code had modified the original this.posts. Being able to opt into this change seems like a good way to find out where the breaks are outside of the full deprecation in emberjs/rfcs#864

@wagenet
wagenet force-pushed the ember-a-improvements branch from 582831f to 331a4a6 Compare March 7, 2023 17:12
@MelSumner
MelSumner requested review from a team and chriskrycho March 24, 2023 21:27
@locks

locks commented Aug 4, 2023

Copy link
Copy Markdown
Contributor

@wagenet I'm working on pushing tracked-built-ins to recommended and saw this PR. Is this something we still want to push forward?

@wagenet

wagenet commented Aug 18, 2023

Copy link
Copy Markdown
Member Author

@locks This was partially motivated by issues Ember Data was having. @runspired what's the status of that stuff?

@runspired

runspired commented Aug 21, 2023

Copy link
Copy Markdown
Contributor

still needed. iirc the solution for most has been to turn prototype extensions back on

@kategengler

Copy link
Copy Markdown
Member

Is this still relevant?

@runspired

Copy link
Copy Markdown
Contributor

@kategengler I believe so

@kategengler

Copy link
Copy Markdown
Member

@wagenet should we merge then?

@wagenet

wagenet commented Jan 10, 2024

Copy link
Copy Markdown
Member Author

@kategengler I would like to and it is flagged so it should be safe. That said, I haven't really gotten a proper review from anyone still.

@kategengler

Copy link
Copy Markdown
Member

@kategengler I would like to and it is flagged so it should be safe. That said, I haven't really gotten a proper review from anyone still.

I don't have a clue here or I would offer you one :) I'm just triaging PRs.

@NullVoxPopuli

Copy link
Copy Markdown
Contributor

can this be rebasod?

@wagenet
wagenet force-pushed the ember-a-improvements branch from 331a4a6 to dd75266 Compare January 11, 2024 16:25
// SAFETY: This will return an NativeArray but TS can't infer that.
return NativeArray.apply(arr ?? []) as NativeArray<T>;
if (EMBER_A_NON_MODIFYING) {
// Remove this in Ember 5.0.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5.0? 😅

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Heh... should be 6.0 now, I guess.

@kategengler

Copy link
Copy Markdown
Member

Since we're planning to deprecate Ember Array and have not yet fixed this, should this be closed?

@kategengler

Copy link
Copy Markdown
Member

Closing since we plan to deprecate Ember Array

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants