w3c / csswg-drafts

CSS Working Group Editor Drafts
https://drafts.csswg.org/
Other
4.47k stars 658 forks source link

[css-contain] If a ResizeObserver callback changes the `content-visibility` of an element, should that prevent observations of the same resize event? #7746

Open mrobinson opened 2 years ago

mrobinson commented 2 years ago

https://w3c.github.io/csswg-drafts/css-contain-2/#cv-notes states:

From the perspective of a ResizeObserver, the skipped contents of an element never change their size. If these elements become non-skipped later, the resize observation will be delivered if the new size differs from the last size used to notify the resize observer.

A ResizeObsever observation callback might change the content-visibility and force layout of an element though. Consider the situation where that freshly-hidden element also has a ResizeObsever triggered by the same resize event. The question here is whether a web engine should trigger an observation callback for the freshly-hidden element.

To me it seems like the specification implies that immediately after content is hidden it should stop receiving any ResizeObserver callbacks, but I believe that there could be multiple interpretations of the passage above.

cc @emilio

A WPT test demonstrating the situation ```html Content Visibility: behavior of ResizeObserver that changes content-visibility
x
x
```
Loirooriol commented 2 years ago

This seems somewhat analogous to #6493:

<div id="test">test</div>
<script>
var ro1 = new ResizeObserver(() => {
  console.log("ro1");
  ro2.unobserve(test);
});
ro1.observe(test);
var ro2 = new ResizeObserver(() => {
  console.log("ro2");
});
ro2.observe(test);
</script>

This should log both ro1 and ro2, i.e. the ro2 callback is invoked even if it's no longer observing any element.

So I think that your testcase should be consistent with this, first determine the active observations, then broadcast them regardless of whether some callback does something that would have avoided some observation.

mrobinson commented 2 years ago

This seems somewhat analogous to #6493:

In this case, should the specification be updated to clarify this?