-
Notifications
You must be signed in to change notification settings - Fork 355
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
Avoid "update prop already used in computation" #802
Conversation
Ember internals use an observer for attribute bindings. In this case the observer timing causes a computation based on a value which is then updated by a side-effect-having CP. Here avoid the observer interaction by instead setting the count itself as part of the computation side effects. See: * Addepar#795 * emberjs/ember.js#18613 Fixes Addepar#795
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.
can't wait to drop support for 1.12/1.13
@@ -306,6 +309,11 @@ export default Component.extend({ | |||
this.collapseTree.set('rowMetaCache', this.rowMetaCache); | |||
this.collapseTree.set('rows', rows); | |||
|
|||
run.schedule('actions', () => { | |||
// eslint-disable-next-line ember-best-practices/no-side-effect-cp | |||
this.set('dataTestRowCount', this.get('wrappedRows.length')); // eslint-disable-line ember/no-side-effects |
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.
do we need two eslint-disable
comments here?
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.
There are indeed two rules which error on this.
It is actually a bit annoying since the side effects really begin on line 309, but I presume the lint only catches on this.set
@@ -306,6 +309,11 @@ export default Component.extend({ | |||
this.collapseTree.set('rowMetaCache', this.rowMetaCache); | |||
this.collapseTree.set('rows', rows); | |||
|
|||
run.schedule('actions', () => { | |||
// eslint-disable-next-line ember-best-practices/no-side-effect-cp | |||
this.set('dataTestRowCount', this.get('wrappedRows.length')); // eslint-disable-line ember/no-side-effects |
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.
if this passes the test then LGTM but obviously this super sucks explicitly adding this sideeffectyness. Thankfully it's pretty limited side effect but still 🤢
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.
Right, as noted this is expanding on an already-existing side effect which caused the problem. An alternative here would be to simply stop offering the data-tests-row-count
attribute. If we drop 1.12 then this would be rewritten using didReceiveAttrs
and the count could be set there without any CP side effects.
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.
Confirmed that this fix will unblock the app I'm working on from upgrading to 3.15 🎉
I believe the remaining failures are un-related to anything in ember-table, instead they should be resolved by ember-cli/ember-cli-htmlbars#423 landing and getting released. |
b63842b
to
e939236
Compare
Avoids the issue with Node 8 caused by npm/node-semver@d61f828#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R35
e939236
to
d923e47
Compare
It is green! I had to add an additional commit to ignore engines wrt: npm/node-semver@d61f828#diff-b9cfc7f2cdf78a7f4b91a753d10865a2R35 This change makes the tests slightly more brittle but we don't need to stop testing with Node 8. Given that this addon nominally supports Node 8 that seems like the right tradeoff. |
Ember internals use an observer for attribute bindings. In this case the observer timing causes a computation based on a value which is then updated by a side-effect-having CP.
Here avoid the observer interaction by instead setting the count itself as part of the computation side effects.
See:
Fixes #795