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

Issue with @tracked #468

Closed
gvocale opened this issue May 8, 2020 · 7 comments · Fixed by #471
Closed

Issue with @tracked #468

gvocale opened this issue May 8, 2020 · 7 comments · Fixed by #471

Comments

@gvocale
Copy link

gvocale commented May 8, 2020

I am running into issues setting and consuming a changeset at the same time.

I have the following in a Glimmer component:

// component.ts
export default class Dummy extends Component {
  @tracked changeset: BufferedChangeset;

  get otherProperty() {
    return this.changeset.property
  }
 
  @action
  setProperty() {
    this.changeset.set('property', {});
  }
}
// template.hbs
{{log this.changeset.property}}

I get the following error:

Error: Assertion Failed: You attempted to update [object Object].property to "[object Object]", but it is being tracked by a tracking context, such as a template, computed property, or observer. In order to make sure the context updates properly, you must invalidate the property when updating it. You can mark the property as `@tracked`, or use `@ember/object#set` to do this.

As you can see changeset is marked as @tracked, but that didn't seem to help.

If I just set the value, without consuming it in the template or another property, I don't get the error.

@gvocale
Copy link
Author

gvocale commented May 8, 2020

Just to add to it, the first time doing this.changeset.set('property', {}); it works, from the second time onwards, the error is thrown.

@snewcomer
Copy link
Collaborator

👋 Thank you for the issue! I have a PR open to provide better ergonomics around Proxy set. One note is @tracked is good for properties that are set (replaced). It looks like you might be modifying keys on the object instead. I'm not 100% sure if this works or not.

@snewcomer
Copy link
Collaborator

This is in fact a problem. At the validated-changeset layer, we use play JS setters. However, using Ember.set is problematic when starting from {} and you want to set a nested path user.email. Currently investigating this limitation and alternative solution in validated-changeset.

@basz
Copy link
Contributor

basz commented May 11, 2020

I'm hitting this error too...

@snewcomer
Copy link
Collaborator

Tracking it. A bit unexpected behaviour from Ember.set so it isn't a straightforward refactor. Hope to get it fixed today.

Screen Shot 2020-05-09 at 3 46 15 PM

@basz
Copy link
Contributor

basz commented May 12, 2020

anything I can do to help?

@snewcomer
Copy link
Collaborator

Thanks @basz! I have a solution in the linked issue. Effectively b/c Ember.set does not handle Ember.set({}, 'user.name', 'foo'), we need to keep our own setDeep logic but when property assignment happens at each level of the tree, we use Ember.set. Will look to get in and update e-c by the end of the day!

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