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

Mutating a card’s payload re-triggers init and didInsertElement #19

Closed
dtetto opened this issue Oct 5, 2016 · 2 comments
Closed

Mutating a card’s payload re-triggers init and didInsertElement #19

dtetto opened this issue Oct 5, 2016 · 2 comments

Comments

@dtetto
Copy link
Member

dtetto commented Oct 5, 2016

To duplicate, create a mobiledoc containing a single card whose component is:

export default Ember.Component.extend({

  click () {
    this.set('payload', {})
  },

  init () {
    this._super(...arguments);

    console.log('init');
  },

  didInsertElement () {
    console.log('didInsertElement')
  },

  willDestroyElement () {
    console.log('willDestroyElement')
  }

});

Each time the component is clicked, the init and didInsertElement hooks are re-triggered, presumably because of a feedback loop caused by modifying the mobiledoc itself (thus triggering a re-initialization and rendering of its child cards). The expected behavior (per Ember lifecycle & DDAU) would be for subsequent re-renders to only trigger the didUpdateAttrs hook (or, less intuitively, to destroy the component and create a new component & context, but that’s not the case currently as willDestroyElement is never called).

This lead to some looping behavior in the wild at (private repo): https://github.com/bustlelabs/nighthawk/issues/219.
Passing all payloads through the (readonly) helper:
https://github.com/bustlelabs/nighthawk/commit/046c033d81683ac30f30ae3ec017cf095bab75da
is one way to address this issue.

@bantic
Copy link
Contributor

bantic commented Oct 11, 2016

@dtetto Thanks for reporting. I have a repro locally and am working on a fix.

@bantic
Copy link
Contributor

bantic commented Oct 19, 2016

fix released in v0.5.3

lukemelia pushed a commit to yapplabs/ember-mobiledoc-dom-renderer that referenced this issue Aug 19, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants