WICG / layout-instability

A proposal for a Layout Instability specification
https://wicg.github.io/layout-instability/
Other
158 stars 26 forks source link

The spec should make it clearer whether `transform` affects "visual representation" and layout shift #66

Open dholbert opened 4 years ago

dholbert commented 4 years ago

The explainer and spec don't seem to agree on what the impact of CSS transform is, with respect to layout shift.

The spec: (1) doesn't mention the word transform at all, ever. (2) Defines layout shift in terms of the "visual representation" (3) Defines "visual representation" in a way that's not immediately obvious as to whether it includes transforms or not. https://wicg.github.io/layout-instability/#sec-basic-concepts

The explainer: (4) ...says that "Changing an element's transform affects its visual representation" (direct quote, emphasis added, note the use of the spec term "visual representation") (5) ...says that transform changes aren't treated as layout shifts https://github.com/WICG/layout-instability/blob/master/README.md#transform-changes

Concerns:

dholbert commented 4 years ago

One other problematic spot with respect to transforms:

In the piece of the spec that excludes scrolling elements (sec 2.2, "there does not exist an Element P such that..."), the spec discusses whether the node N's position has changed within its scroll-container's "scrollable overflow region".

And importantly, transform does change an element's position within (and its contribution to) this scrollable overflow region. Here's a demo which changes transform of something in a scrollport on hover: https://jsfiddle.net/dholbert/n937w14L/ (note that the scrollbars change when transform changes, indicating that the scrollable overflow area has changed size, and obviously the transformed thing has changed position within it).

So it seems that at least this section of spec text does not exclude transforms right now - it would consider transforms as contributing to layout instability. That may be problematic...?

(EDIT: this comment might be addressed by https://github.com/WICG/layout-instability/issues/67 -- initially I was going under the stricter "Interpretation B" that I describe over there, but maybe the real intent is the other interpretation.)

npm1 commented 4 years ago

Looking at tests, looks like modifying transform should not result in an entry (https://github.com/web-platform-tests/wpt/blob/master/layout-instability/transform-change.html), but transform needs to be considered when computing viewport overlap (https://github.com/web-platform-tests/wpt/blob/master/layout-instability/transform.html).

clelland commented 1 year ago

My understanding here is that CSS transforms are deliberately not included in this spec, because changing them does not induce layout -- no other elements on the page need to be adjusted because of a change to transform. (Yes, this is despite the fact that it absolutely does affect the visual representation of the element being transformed)

@npm1's note about the viewport overlap is certainly relevant, though, as a transformed element may be the container of other elements which are subject to layout shifts -- the layout of elements within a transformed container should probably be considered.