Re: [whatwg/dom] Make it possible to observe connected-ness of a node (#533)

trusktr left a comment (whatwg/dom#533)

<details><summary>@FrameMuse unrelated to the original discussion, but it is actually impossible to detect when an element is finally painted:</summary>

> Currently, the moment when a element is reflowed can be accurately caught with this snippet. Obviously, I would like to have a more general approach to receiving this event.
> 
> export function onElementPainted(target: Element, callback: () => void) {
>   new ResizeObserver((_, observer) => {
>     callback()
>     observer.unobserve(target)
>   }).observe(target)
> }

That's not good enough because if some other resize observer callback changes the size (directly or indirectly) of the element, it is possible that more resize callbacks will subsequently be queued and fired. The only sure thing we can do is keep the resize observer enabled the whole life of the element, instead of unobserving it right away, otherwise some reflows may be missed.

But note that reflow is not the same as paint, and it is impossible to run logic after paint. The "paint" doesn't happen until *after all resize observer callbacks*, and it is impossible to register a callback that will run after all `ResizeObserver` callbacks are finished.



</details>



-- 
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/dom/issues/533#issuecomment-2833645424
You are receiving this because you are subscribed to this thread.

Message ID: <whatwg/dom/issues/533/2833645424@github.com>

Received on Sunday, 27 April 2025 21:19:29 UTC