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

Computed Properties broken with @each in 2.1.0 #12475

Closed
ameliadowns opened this issue Oct 12, 2015 · 66 comments
Closed

Computed Properties broken with @each in 2.1.0 #12475

ameliadowns opened this issue Oct 12, 2015 · 66 comments

Comments

@ameliadowns
Copy link

Every computed property based on something using @each has broken with the 2.1.0 upgrade. Here are two examples:

  titleUniqueInCollection: Ember.computed('collection.sections.@each.title', function() {
    const sections = this.get('collection.sections');
    const sectionsWithSameTitle = sections.filterBy('title', this.get('title'));
    return sectionsWithSameTitle.length === 1;
  }),
  sortedCollectionItems: Ember.computed('collectionItems', 'collectionItems.@each.rankPosition', function() {
    return this.get('collectionItems').sortBy('rankPosition');
  }),

The functions are no longer running as expected when an attribute is changed.
Edited to reflect @stefanpenner's comment.

@stefanpenner
Copy link
Member

can you provide a jsbin or similar to demonstrate the issue in isolation.

Also some little things, hopefully to prevent future confusion:

  • these aren't observers just computed properties
  • they don't fire, rather in two in they will be marked as dirty, and if someone is interested they will consume (but only if someone like an active template chooses to)

@ameliadowns ameliadowns changed the title Observers broken with @each in 2.1.0 Computed Properties broken with @each in 2.1.0 Oct 12, 2015
@e00dan
Copy link
Contributor

e00dan commented Oct 12, 2015

I wonder if this is related to #12328.

@ameliadowns
Copy link
Author

Here's a JS Bin.

I added a broken computed property to @kuzirashi's JS Bin from #12328

@stefanpenner
Copy link
Member

may be related to -> #11983 / #11984 / #11983 cc @krisselden

@adam-knights
Copy link

Is this likely to be a 2.1 patch or should we plan to wait for 2.2?

@g-cassie
Copy link

Also looking for guidance on here as to whether this will get patched or if we are looking at a fix for 2.2. If there is anything that a novice can do to help move things along please let me know.

@rwjblue
Copy link
Member

rwjblue commented Oct 30, 2015

@g-cassie - I haven't had time to really dig into this, but if a fix is proposed it will definitely be in 2.2 and depending on how invasive it is we could backport to 2.0/2.1 as needed. The first step is that someone needs to figure it out and fix the bug.

@davidsteinberger
Copy link

@ameliadowns @g-cassie I'm facing the same issue. Has either of you found a way to get the CP listening to @each.property_name to recompute?

@g-cassie
Copy link

g-cassie commented Nov 2, 2015

@davidsteinberger I just reverted to Ember 2.0 for the time being. The problem seems to be isolated to 2.1

@krisselden
Copy link
Contributor

@stefanpenner have you or anyone on this thread confirmed that one of those PRs mentioned caused this issue? I'll try to get to this soonish, it would help to have a failing test PR if anyone interested in this issue wants to see it addressed sooner.

@g-cassie
Copy link

g-cassie commented Nov 2, 2015

@krisselden I think #12538 is a failing test PR for this issue.

@ameliadowns
Copy link
Author

@davidsteinberger, I did the same as @g-cassie and reverted to Ember 2.0.

@stefanpenner
Copy link
Member

@krisselden no i have not yet had a chance.

@stevesims
Copy link

+1 from me
We're seeing this issue in our codebase too - we've got a CP that has a dependent key of record.relatedItem.@each.hasDirtyAttributes which never updates. even when one of the relatedItem records definitely becomes dirty.
I suspect we'll need to revert to Ember 2.0 as well to work around this

@adam-knights
Copy link

@g-cassie I took a look at your test and I think it fails in Ember 2.0 too so not sure it shows this issue.

@andorov
Copy link

andorov commented Nov 12, 2015

I have seen an issue with an array observer ('[]' and not '@each', but possibly the same root cause) not triggering in Ember 2.0.0

@stevesims
Copy link

Further to my earlier note, as per emberjs/data#3911 we've worked around by using a dependent key of record.relatedItem.content.@each.hasDirtyAttributes, so fortunately we haven't had to revert to 2.0
Would still be very nice to see this fixed.

@adam-knights
Copy link

I tried Ember 2.2.0 today and we still see issues with @ each.

@toovy
Copy link

toovy commented Dec 8, 2015

I can confirm that this is still not working in v2.3.0-beta.2.

@adam-knights
Copy link

I've played around with some of the unit tests at various levels and I have yet to find something that passes in ember 2.0 and fails in 2.1/2.2, including the pull request above. Has anyone been able to see this regression with non ember data objects?

@csantero
Copy link
Contributor

csantero commented Dec 8, 2015

@adam-knights I believe this has been broken since at least 2.0. I tested a version of that PR against each major release and the last one it was working on was 1.13.

@adam-knights
Copy link

@csantero I'd love to do some work to help identify the exact commit that did this but my issue was getting your PR to pass on 1.13, I never got it passing, did you modify it in some way?

@csantero
Copy link
Contributor

csantero commented Dec 8, 2015

@adam-knights IIRC the file with related tests moved between then and now, but otherwise the test was the same.

@YoranBrondsema
Copy link
Contributor

FWIW we're seeing the same issue which prevents us from upgrading to Ember 2.1.

@nybblr
Copy link

nybblr commented Jan 14, 2016

Same issue on a project I'm running w/ Ember 2.2, happens when observing through PromiseManyArrays.

Interestingly, if I render a property in a template (forcing an access) within the .@each, it forces a recompute I guess and observation works.

@stefanpenner
Copy link
Member

Sorry guys, the last little while has been hectic. I'll try to carve out some time in the next week or so (feel free to ping me If i don't respond again in a week, that means I just forgot).

@jeradg
Copy link
Contributor

jeradg commented Jan 14, 2016

@stefanpenner You're a champ.

ef4 added a commit that referenced this issue Jan 18, 2016
This adds a failing test for #12475. It appears that `obj.set('array', [a1, a2, a3])` fails to install contentKey observers on the new array value so that the subsequent changes to `foo` are ignored.
ef4 added a commit that referenced this issue Jan 18, 2016
This adds a failing test for #12475. It appears that `obj.set('array', [a1, a2, a3])` fails to install contentKey observers on the new array value so that the subsequent changes to `foo` are ignored.
stefanpenner added a commit that referenced this issue Jan 19, 2016
* reduces EF4’s case further
* move related tests to runtime/computed/chains
* adds more thorough tests revealing more related issues
@ef4
Copy link
Contributor

ef4 commented Jan 19, 2016

Folks who are watching this issue and interested in exploring the problem should check out the test cases in #12832

It looks like there is at least one longstanding bug in ember-metal that's contributing to this problem, and it was revealed by more recent changes.

@stefanpenner
Copy link
Member

@jgwhite that is not a supported behavior, you can only go one leaf beyond the @each

@runspired / @jgwhite we should make this a warning. It is a trap, and seemed to work, due to performance bug.

@jgwhite
Copy link
Contributor

jgwhite commented Jan 20, 2016

@stefanpenner good idea. Submitted my attempt in #12847.

@mmun
Copy link
Member

mmun commented Jan 23, 2016

Hey @fivetanley, I had a similar bug in my app that I was able to bisect down to the same commit. With the help of @krisselden, I believe the issue is that the offending PR changed content to be a computed property, but this computed property is clobbered by https://github.com/emberjs/data/blob/c8f03a5c1c7b91160e6c3ad51b80638efd1b0413/addon/-private/system/record-arrays/record-array.js#L44. It may also be clobbered in other places. I haven't looked closely yet.

We should first try to rewrite the PR in a way that does not use a CP (and back port fixes to 2.1, 2.2 and 2.3) so that other consumers of ArrayProxy don't have the same issues. If that strategy fails we can change ember-data to not clobber instead.

mmun added a commit to mmun/ember.js that referenced this issue Jan 24, 2016
Fixes emberjs#12475.

This commit restores the contract of ArrayProxy content being a simple
property instead of a computed property. This prevents accidental
clobberings such as in ember-data:

https://github.com/emberjs/data/blob/v2.3.3/addon/-private/system/record-arrays/record-array.js#L44

This commit also removes a private hook `arrangedContentArrayWillChange`.
In the interest of keeping this bugfix commit minimal, we will continue
removing the will* hooks on canary.
mmun added a commit to mmun/ember.js that referenced this issue Feb 3, 2016
rwjblue added a commit that referenced this issue Feb 4, 2016
@gabrielrotbart
Copy link

Thanks a lot @mmun. Really appreciated, even though the solution is not ideal

rwjblue pushed a commit that referenced this issue Feb 5, 2016
(cherry picked from commit 7a74435)
rwjblue pushed a commit that referenced this issue Feb 5, 2016
(cherry picked from commit 7a74435)
@YoranBrondsema
Copy link
Contributor

@mmun Thanks for fixing! One question though: as far as I can see, the bugfix #12908 has only been released for 2.3 and 2.4. However, this bug is preventing us from upgrading from 2.0 to 2.1. We would like to avoid having to upgrade straight to 2.3 from 2.0. Would you be able to do a bugfix release for 2.1 and 2.2 as well? Or has the code diverged too much and is causing many conflicts.

@rwjblue
Copy link
Member

rwjblue commented Feb 8, 2016

We generally do not backport bugfixes to all affected versions. 2.0/2.1/2.2/2.3 are all compatible versions, I am not aware of any breaking changes amongst them.

@stefanpenner
Copy link
Member

Or has the code diverged too much and is causing many conflicts.

Its just a time thing, maybe someday we will have more of it 💀

@hoIIer
Copy link

hoIIer commented Mar 21, 2018

just ran into this on ED 3.0.2 where:

    productCount: computed('cart_lines.@each.quantity', function() {

if triggered upon line item create but not upon quantity update of existing. however this:

    productCount: computed('cart_lines.content.@each.quantity', function() {

does fire when it updates... is this supposed to still be happening in the latest Ember Data?

@mmun
Copy link
Member

mmun commented Mar 21, 2018

@erichonkanen The bug that you're describing is another bug that has been fixed on ember-data master.

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

Successfully merging a pull request may close this issue.