Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[css sizing] auto <length> description may have wrong "otherwise" #7769

Closed
hamishwillee opened this issue Sep 20, 2022 · 9 comments
Closed

Comments

@hamishwillee
Copy link

For contain-intrinsic-size: auto <length> my understanding is that the intent is that if the content has never been rendered you won't have a remembered value, so you will use the length value for size constrained layout. If however you have ever been able to render the content you will have a remembered value for the size, and you'll use that instead.

The spec here does not appear to say that.

The first part implies it:

auto <length>
If the element has a last remembered size and is currently skipping its contents, its explicit intrinsic inner size is the last remembered size.

Note: This occurs, for example, when an element with content-visibility: auto is off-screen.

My interpretation of that is that you use the remembered value when you are offscreen and have a remembered value and have auto set. That makes sense - you're using a remembered value because you can't recalculate one.

But then the spec says:

Otherwise, its explicit intrinsic inner size is the specified <length>.

That "otherwise" is all other cases. To me that means that if you are not skipping the contents you will use length. I suspect in most cases you won't be using size containment, but if you are, this means you aren't using the remembered value even if you could.


As an aside, the following paragraph reads as gibberish:

If an element has an explicit intrinsic inner size in an axis, then after laying out the element as normal for size containment, the size of the contents in that axis are instead treated as being the explicit intrinsic inner size instead of what was calculated in layout, and layout is performed again if necessary. (If it has an explicit intrinsic inner size in both axises, this implies the first layout can be skipped.)

I may just be completely missing the point but "after laying out the element as normal for size containment" should means that there is nothing calculated in the layout.

@Loirooriol
Copy link
Contributor

To me that means that if you are not skipping the contents you will use length

Yes, that was deliberate, see #6308.

the following paragraph reads as gibberish

Yes, see #7519. @tabatkins said he would add some examples to clarify what the text is trying to say.

@hamishwillee
Copy link
Author

@Loirooriol Thanks. I don't see how that follows from #6308 . That's about making sure that the onscreen element is not rendered with outdated dimensions. It makes sense not to render using a remembered value. But what I think this text stays is that you would in this case render with <length> which is also an outdated dimension in that it's a guess at what the element might be. Right?

I will look at the #7519 examples.

Thanks for considering the comments. I appreciate that they probably seem a bit stupid when you understand all the context.

@Loirooriol
Copy link
Contributor

To avoid using the outdated dimension, it's using the specified <length> instead of the last remembered size. The <length> is not outdated, it's a value explicitly provided by the author, if the author wants another value they can update contain-intrinsic-size.

@hamishwillee
Copy link
Author

hamishwillee commented Sep 20, 2022

Ah! The logic I saw "somewhere" for providing auto was that it helps because getting the <length> correct can be difficult and using auto is likely to result in values that are closer to the actual rendered size. I guess a preference for the developer supplied value reduces surprises. Thank you.

@hamishwillee
Copy link
Author

I guess I should outline my concern with a real case.

Imagine you have an offscreen element that has content visibility: auto. It has a remembered value and since it is offscreen and the contents are being skipped, this is value is being used for layout.

The user scrolls the element near to the view so the user agent starts rendering the elements. At this point it starts using the length because it is not skipping the child elements.

  1. Wont there potentially be some kind of visual effects due to the switch over?
  2. Why ever both user using auto? How is it better to store the value when you're always going to be switching to length at some point?

@Loirooriol
Copy link
Contributor

The user scrolls the element near to the view so the user agent starts rendering the elements. At this point it starts using the length

In that case the element will no longer skip its contents, and thus won't have size containment (unless you are also using e.g. contain: size). So the element will use the actual intrinsic size from the contents instead of contain-intrinsic-size.

Wont there potentially be some kind of visual effects due to the switch over?

Possibly, if e.g. the contents have changed (i.e. the last remembered size was outdated). But in most cases it should work well enough.

Why ever both user using auto?

To mitigate these visual effects, like the scrollbar thumb jumping around, see #5668. Switching from an old non-contained size to the current non-contained size is probably better than switching from some poorly guessed length.

And note you can pair contain-intrinsic-size: auto with content-visibility: hidden, which will use the last remembered size even if the element is relevant to the user.

@Loirooriol
Copy link
Contributor

OK, I guess you might be arguing that the condition of skipping the contents could be replaced with having a non-visible content-visibility?

So, the answer of "If the element has size containment, should it use the last remembered size?" is:

Nothing else causing
size containment
contain: size
or similar
content-visibility: visible - No
content-visibility: auto not skipping contents - No
content-visibility: auto skipping contents Yes Yes
content-visibility: hidden Yes Yes

And it would become:

Nothing else causing
size containment
contain: size
or similar
content-visibility: visible - No
content-visibility: auto not skipping contents - Yes
content-visibility: auto skipping contents Yes Yes
content-visibility: hidden Yes Yes

I don't think it matters much in practice since contain: size or similar will prevent storing the last remembered size in the 1st place, so only observable if you are setting it dynamically.

@hamishwillee
Copy link
Author

@Loirooriol My concerns here are answered.

I was mostly concerned about the case when the element is coming into view from offscreen - i.e. why you would choose not to use the remembered size in this case. You answered this two comments above in #7769 (comment); it's because you're not in size containment anymore so you're not skipping the content. IN other words you're not using the length OR the remembered size.

"remembering" is a way of getting the benefits of size containment when you're offscreen without actually having to "think about it". If something is actually "planned" to be size contained and is visible then using the user-supplied length makes sense.

Thanks for taking the time to spell it out for me. Closing this - I'll keep an eye on #7519

@Loirooriol
Copy link
Contributor

I think it may be worth discussing whether to improve the case with both content-visibility: auto and contain: size, so filed #7807.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants