ember-ast-hot-load
ember-ast-hot-load copied to clipboard
Trigger `did-update` lifecycle modifier on reload
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.
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
...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.
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)