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

Avoid "update prop already used in computation" #802

Merged
merged 2 commits into from
Jan 9, 2020

Conversation

mixonic
Copy link
Member

@mixonic mixonic commented Jan 8, 2020

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

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
Copy link
Contributor

@twokul twokul left a 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
Copy link
Contributor

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?

Copy link
Member Author

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
Copy link
Contributor

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 🤢

Copy link
Member Author

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.

Copy link
Member

@kpfefferle kpfefferle left a 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 🎉

@mixonic
Copy link
Member Author

mixonic commented Jan 8, 2020

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.

@mixonic mixonic force-pushed the mixonic/3.15-compat branch from b63842b to e939236 Compare January 9, 2020 20:58
@mixonic mixonic force-pushed the mixonic/3.15-compat branch from e939236 to d923e47 Compare January 9, 2020 21:05
@mixonic
Copy link
Member Author

mixonic commented Jan 9, 2020

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.

@mixonic mixonic merged commit b24e98e into Addepar:master Jan 9, 2020
@mixonic mixonic deleted the mixonic/3.15-compat branch January 9, 2020 21:28
@jiayingxu
Copy link
Contributor

@mixonic with this change, the rowCount on the table body is not accurate for tree tables. I created #804 to track this.

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

Successfully merging this pull request may close these issues.

tests breaking with Ember v3.15
5 participants