component-register icon indicating copy to clipboard operation
component-register copied to clipboard

Question: how to handle reconnect properly?

Open zhaoyao91 opened this issue 3 years ago • 1 comments

Standard web component has 3 key lifecycle point: create(constructor), connected, disconnected. This is because an element may be remove from dom and added back again and again. With these hooks, we could create something in constructure but reuse them from time to time.

But lifecycles defined by this repo are only create and release, which means we have to recreate all thing after reconnecting.

Am I missing something? Or how could we handle this?

zhaoyao91 avatar Apr 06 '21 16:04 zhaoyao91

Yeah. I built this so that while it can handle moves that when the element has been disconnected I free up reactivity (basically dispose) and when connected I create again. I'm not sure if there is a way around this because otherwise we'd have potential memory leaks and there is no onDispose hook in the native DOM only disconnect. I have no way to automatically cleanup after ourselves.

Not sure if there is some clever trick I'm missing but this is just one of those things that I've considered from the beginning since I was dealing with reactive libraries which innately have leaky observer potential. Using something like a WeakMap is non-starter since besides not being able to change other libraries internals they can't be iterated on as subscriptions. We need a definite even to tie into to free up long live subscriptions. At which point we need to re-evaluate all those computations again which I basically can't do without recreation.

ryansolid avatar Apr 06 '21 17:04 ryansolid