[csswg-drafts] [resize-observer] Browsers trigger on initial observe of disconnected element, contrary to spec (#11280)

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

== [resize-observer] Browsers trigger on initial observe of disconnected element, contrary to spec ==
There seems to be disagreement between the resize-observer spec and browser implementations as to whether observing a disconnected element should trigger an immediate callback, as in the following code:

```js
let disconnectedEl = document.createElement("div");
let observer = new ResizeObserver((entries) => {
  console.log("Got callback:", entries);
});
observer.observe(disconnectedEl);
```

## Behavior according to resize-observer spec

The resize-observer chapter [§ 1. Introduction](https://drafts.csswg.org/resize-observer/#intro) lists the following among the "interesting facts":

> 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 rest of the spec does seem to agree with this conclusion: Section [§ 3.1. ResizeObservation example struct](https://drafts.csswg.org/resize-observer/#resize-observation-interface) says that `lastReportedSizes` is initialized to `[(0,0)]`, and the `isActive()` function compares the element's `currentSize` (which is its `computedSize`) to that. But the `computedSize` of a disconnected element should be `0,0`, and thus `isActive()` should be false.

## Current browser behavior

Running the code above, Chrome, Firefox and Safari all print

```
Got callback: Array [ ResizeObserverEntry ]
```

where the box sizes in the `ResizeObserverEntry` array are indeed all `0,0`.

## Suggested resolution

I'm not sure whether the browser behavior should be changed, or the spec should be brought in line with browsers' actual behavior.

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


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

Received on Wednesday, 27 November 2024 15:14:24 UTC