adopted-ember-addons / ember-changeset

Ember.js flavored changesets, inspired by Ecto
http://bit.ly/ember-changeset-demo
MIT License
431 stars 141 forks source link

Errors with Ember v3.22 #553

Closed josemarluedke closed 4 years ago

josemarluedke commented 4 years ago

Just tried upgrading an app to Ember v3.22 and started getting some errors in changeset.

index.js:172 Uncaught (in promise) Error: Assertion Failed: You attempted to update `_changes` on `changeset:[object Object]`, but it had already been used previously in the same computation.  Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.

`_changes` was first used:

The same happens with _errors as well.

image

Version

changeset v 3.8.2 (also tested with latest version but same occurs. ) ember v 3.22

snewcomer commented 4 years ago

@josemarluedke Happen to know if it tracks back to your codebase or do all signs point to this addon?

I certainly have seen this many times and I know work has been done in emberjs to address some of these things. Also here is an ember-data issue with similar problems (only in development). There is still one PR to land below as well.

https://github.com/emberjs/data/issues/7196 https://github.com/glimmerjs/glimmer-vm/pull/1111

josemarluedke commented 4 years ago

@snewcomer I apologize. You are right, the issues were not in the addon itself, but rather how I was interacting with it.

I had two main issues:

  1. I was calling changeset.set on my component constructor.
  2. I was calling validate twice in the same time, I guess. See PR: https://github.com/josemarluedke/frontile/pull/96

I do wonder if the second issue could be avoided somehow in the addon?

Thanks for quickly confirming that there were no issues in the addon.

snewcomer commented 4 years ago

It is an interesting question. I can see both sides. I might lean one way though. Since these errors can be triggered with an infinite number of user land examples and is a necessity in protecting data integrity, my feeling is it should always be on the user. We might be chasing our tail if any data mutation hook needed to protect against this scenario.

snewcomer commented 3 years ago

FYI -

https://github.com/emberjs/ember.js/issues/19192

ijlee2 commented 3 years ago

Hi, @snewcomer. After upgrading ember-source from v3.22.0 to v3.22.1 in my app, I'm still encountering the error message when I press the Enter key to save a changeset.

You attempted to update `_errors` on `changeset:[object Object]`, but it had already been used previously in the same computation.  Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.

In order for this message to go away, would ember-changeset or ember-changeset-validations itself need to use ember-source v3.22.1 (i.e. would a new release be needed)?

ijlee2 commented 3 years ago

@snewcomer I realized that the error was my fault, my apologies.

I was updating the changeset on an input's focusout event as well as Enter key press. When I submitted the input by pressing Enter and made a route transition afterwards, the input field lost focus, triggering the focusout event. I believe this caused the changeset to update twice instead of once.

sinankeskin commented 3 years ago

Hi everyone.

I'm trying to upgrade one of our app to Ember v3.22 and seeing a lot of this deprecations. I'm just creating a changeset and setting value to a property.

What's the best way to avoid this? @snewcomer

DEPRECATION: You attempted to update_changesonchangeset:[object Object], but it had already been used previously in the same computation. Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.

Thanks.

snewcomer commented 3 years ago

@sinankeskin 👋 This is similar to this case. You might have to adjust when/how the changes is created then updated. The problem is something was read-then-written in the same computation in the same "tick".

https://github.com/poteto/ember-changeset/issues/602

sinankeskin commented 3 years ago

@sinankeskin 👋 This is similar to this case. You might have to adjust when/how the changes is created then updated. The problem is something was read-then-written in the same computation in the same "tick".

https://github.com/poteto/ember-changeset/issues/602

I've fixed this with a creating middle classes. Works perfect now. Thanks a lot @snewcomer Appreciated.