WICG / input-for-workers

Specification for exposing input events to workers
Other
25 stars 6 forks source link

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

Open majido opened 4 years ago

majido commented 4 years ago

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.