[csswg-drafts] [resize-observer-1] Firing observations on insert/remove when rendered size is (0, 0) (#7808)

vmpstr has just created a new issue for https://github.com/w3c/csswg-drafts:

== [resize-observer-1] Firing observations on insert/remove when rendered size is (0, 0) ==
The group resolved to initialize the initial observation to (-1, -1) here: https://github.com/w3c/csswg-drafts/issues/3664#issuecomment-1218270926

I don't believe this is sufficient to satisfy the following listed properties of resize observer:

> * Observation will fire when watched Element is inserted/removed from DOM.
> * Observation will fire when watched Element [display](https://www.w3.org/TR/css-display-3/#propdef-display) gets set to none.
> * Observation will fire when observation starts if Element is [being rendered](https://html.spec.whatwg.org/#being-rendered), and Element’s size is not 0,0.

(the 0,0 part of the last point would presumably change due to (-1, -1) resolution)

The way the observations are fired is through some indirection but essentially this text:

> **isActive()**
> * Set currentSize by [calculate box size](https://drafts.csswg.org/resize-observer/#calculate-box-size) given target and observedBox.
> * Return true if currentSize is not equal to the first entry in this.[lastReportedSizes](https://drafts.csswg.org/resize-observer/#dom-resizeobservation-lastreportedsizes).
> * Return false.

Initializing the last reported sizes to (-1, -1) means that
1. Naively we will fire the observations even if the element is not yet being rendered, the implementations need to consider that case separately when computing the currentSize value.
2. After the initial observation, (0, 0) or not, we add the lastReportedSizes entry for that size. This means that when the element is removed, the observation will only fire if the rendered size was not (0, 0). This seems to go against the first point on firing observation on insertion/removal. Likewise when the element is inserted again, it would only fire an observation if the rendered size is not (0, 0).

Although it's in the spec, I don't believe Blink implementation the lastReportedSizes is an exposed property. I'm not sure about other implementations. One solution would be to add a new (-1, -1) entry any time the element is removed or display: none or loses its "being rendered" status in any way. It's a little awkward. Another option if lastReportedSizes is indeed not exposed anywhere would be to rewrite the resize observer spec to only keep track of one nullable lastReportedSize, have it be null as the initial value, and reset it to null any time the element loses its box

@Loirooriol 

Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/7808 using your GitHub account


-- 
Sent via github-notify-ml as configured in https://github.com/w3c/github-notify-ml-config

Received on Wednesday, 28 September 2022 19:45:57 UTC