ember-ast-hot-load icon indicating copy to clipboard operation
ember-ast-hot-load copied to clipboard

Trigger `did-update` lifecycle modifier on reload

Open nwhittaker opened this issue 3 years ago • 3 comments

Is it possible to trigger the did-update lifecycle modifier on reload?

Consider a case where @user takes a few seconds to populate:

<div {{did-update this.createThumbnail @user}}>
    <img src={{this.thumbnailSrc}} />
</div>

On the first render, the thumbnail is created when @user is populated. However, if I edit only this template, and hot-load re-renders the template, I'm left seeing a broken image because this.createThumbnail does not run for the updated template.

nwhittaker avatar May 14 '21 21:05 nwhittaker

Hi @nwhittaker, nope, because during hot-reload we don't "rerender" component, we removing it, and applying back (count it as a new render, not update)

For hot-reload case only did-insert modifier should work

lifeart avatar May 22 '21 11:05 lifeart

...during hot-reload we don't "rerender" component, we removing it, and applying back (count it as a new render, not update)

I guess I'm mainly wondering if there's a way to restore the component's previous state? I was thinking replaying did-update would be an easy-ish way to do that.

I realize there are other use-cases where this may not be the "happy path", though. And the complexity of the implementation could easily outweigh the value.

Thanks for the consideration.

nwhittaker avatar May 24 '21 15:05 nwhittaker

component state is quite complex thing (except pure components or stateless), we have to track arguments-based state change and event-based (and DOM events may bubble to component from child components)

in short: nope it's likely impossible for generic ember/glimmer components

but, it's possible to implement if you use your own component manager, you could keep component state as not-related to component instance object and reassign it to new component instance

a-la react hooks style (https://github.com/lifeart/hooked-components)

also, it's possible to keep component state, if global state used for it (redux, etc)

lifeart avatar May 24 '21 15:05 lifeart