Description
#5668 added contain-intrinsic-size: auto
, whose purpose was addressing this problem:
One undesired effect of content-visibility: auto is that the scrollbar thumb tends to jump around when content enters and exits the visibility region. This is due to the fact that we keep adding and removing size containment in order for us to optimize rendering of skipped content. The contain-intrinsic-size property helps, but the size still keeps changing between the "real" intrinsic size and contain-intrinsic-size placeholder. The two sizes are frequently different.
contain-intrinsic-size: auto
remembers the non-contained size, bringing stability.
Then #6308 restricted using the last remembered size to when the element skips its contents, so basic contain: size
doesn't use the last remembered size. The reasoning was that the last remembered size can be out of date, so it can be bad to use it for elements which are visible in the screen.
So main cases have stability:
- An element with
content-visibility: auto
will remember its non-contained size when visible, then if it goes off the screen it will skip its contents and get containment, using that last remembered size. If it comes back into the screen, it will lose containment and its size will be updated, but in common cases this will be the same as the last remembered size. - An element with
contain: size
never uses the last remembered size, so it keeps a consistent size regardless of whether it goes off or into the screen.
But imagine this corner case:
- An element has
contain-intrinsic-size: auto 100px; content-visibility: auto
- It's visible in the screen, so it doesn't have containment, and its normal size is remembered, e.g. 15px.
- Then it gets
contain: size
. It's still not skipping its contents, so it's resized to 100px. - The last remembered size is not updated, since it has size containment.
- The element moves off the screen, so it skips its contents, which changes the size into the remembered 15px.
- The element moves back into the screen, so it stops skipping its contents, and becomes 100px.
So the behavior is not stable at all! Here you have a testcase, try scrolling from the top to the bottom and viceversa using the mouse wheel. The scrollbar thumb behaves strangely.
It's an edge case since mixing content-visibility: auto
and contain: size
is maybe a weird combination, and contain: size
needs to be delayed in order to have a last remembered size. But should we try to improve it? Some ideas:
- Change the requirement for using the last remembered size. Instead of skipping the contents, check that
content-visibility
is notvisible
. Size containment will still be needed of course, so the basic case with justcontent-visibility: auto
will not be affected. - Change the requirement for updating the last remembered size. Instead of not having size containment, check that the element doesn't skip its contents (since the last remembered size will only be used when skipping the contents).
CC @vmpstr, @hamishwillee