input-for-workers icon indicating copy to clipboard operation
input-for-workers copied to clipboard

Lifetime of the delegated event target in relationship with original event target

Open majido opened this issue 5 years ago • 0 comments

The expectation is that when on calls worker.addEventTarget(target) on main thread, the worker will receive the delegated target via the following handler.

// in worker
addEventListener("eventtargetadded", ({delegated_target}) => {
  delegated_target.addEventListener("pointermove", onPointerMove);
});

One question that needs to be answered is what is the lifetime of delegated_target? I think the expectation is that the developer should be responsible for calling removeEventTarget and also ensure they handle the eventtargetremoved correctly on the worker side and remove any added event listeners.

What happens when the original DOM element gets removed? Do we collect the delegated target? Do we dispatch eventtargetremoved for it? I worry without doing anything it will be easy to leak memory on the worker.

majido avatar Sep 04 '19 18:09 majido