Re: [csswg-drafts] [css-contain] content-visibility: auto visibility check timing needs details (#8542)

Hi all,

Thank you for providing feedback at the working group meeting, it was valuable! i indeed missed the interaction between determining content-visibility visibility state and resize observer potentially creating new elements. I’ve also learned (from @flackr) that this type of change to the Update the Rendering loop was also used by the animation timelines.

We have elements with some CSS properties (like scroll timelines and content-visibility) that may need a second style+layout update on first load to avoid a flash of uninitialized content. Also, ResizeObserver callbacks can mutate the DOM and bring more such elements into existence. That means we need a loop that considers both. In essence, these scroll timeline and content-visibility aspects can be viewed as a special kind of internal lifecycle observer that are usually async, but are sync on first load.

In light of these things, I think we should update the wording for Update the Rendering “resize observer loop”, i.e [step 14 of Update the Rendering](https://html.spec.whatwg.org/multipage/webappapis.html#processing-model-8), to admit the possibility of steps unrelated to resize observer into the loop that updates style and layout.

Specifically, we could write something like the following. Note that I’ve only pulled some wording from the animations spec here, I’m not an expert in those steps. IOW, the exact wording is something we can debate, but I wanted to propose this as a general idea for updating the loop language:

```
14. For each fully active Document doc in docs:
    1. Initialize state tracking variables:
        1. Let `resize observer depth` be 0.
        2. Let `stale animation timelines updated` be a boolean with value false
    2. Recalculate styles and update layout for doc.
    3. If there are stale animation timelines created during step 14.2 (https://drafts.csswg.org/scroll-animations-1/#html-processing-model-event-loop; related: https://github.com/w3c/csswg-drafts/issues/8694 for possibly changing this) and `stale animation timelines updated` is false:
        1. Update the stale animation timelines
        2. Set `stale animation timelines updated` to true
        3. Go back and resume the algorithm from step 14.2
    4. If there are content-visibility elements with undetermined visibility:
        1. Synchronously determine those element’s visibility
        2. If the visibility update is from undetermined to visible, then go back and resume the algorithm from step 14.2
    5. Gather active resize observations at depth `resize observer depth` for doc. If doc has active resize observations:
        1. Set `resize observer depth` to the result of broadcasting active resize observations given doc.
        2. go back and resume the algorithm from step 14.2
    6. If doc has skipped resize observations, then deliver resize loop error given doc.
```
(sorry about formatting, the numbered lists are hard with indents)

Another item that may belong here is the contain-intrinsic-size last remembered size changes that went through the group, since a lot of the last remembered size changes, like “forgetting the size” are specced to be “at resize observer timing”. However, this one wouldn’t require a repeat of the loop.

-- 
GitHub Notification of comment by vmpstr
Please view or discuss this issue at https://github.com/w3c/csswg-drafts/issues/8542#issuecomment-1515216159 using your GitHub account


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

Received on Wednesday, 19 April 2023 18:54:19 UTC