Skip to content

[css-viewport] Behavior of segments when there is only 1 segment #11957

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

Closed
bramus opened this issue Mar 18, 2025 · 8 comments
Closed

[css-viewport] Behavior of segments when there is only 1 segment #11957

bramus opened this issue Mar 18, 2025 · 8 comments

Comments

@bramus
Copy link
Contributor

bramus commented Mar 18, 2025

The spec currently reads the following for the segments property of window.viewport

  1. Returns null if there is only a single viewport segment and abort these steps.

This very counterintuitive when trying things out and I would have expected for 1 segment to reported, with its values at origin 0,0 and its width/height equal to the innerWidth and innerHeight respectively.

Admittedly the fallback authors can do is pretty easy here, yet I still find it weird to return null as currently specced. That keyword is typically reserved to indicate that there is no value or there is no such thing, whereas there is definitely 1 segment here.

Having it return 1 segment would also help distinguish the 1 segment situations vs “the document is currently not active” situation. The latter also returns null, as per spec:

  1. If the Viewport’s associated Document is not fully active, return null

In summary, the proposed change is to return 1 segment instead of null when there is only 1 segment.

/cc @darktears

@darktears
Copy link
Contributor

darktears commented Mar 18, 2025

This has been discussed in the past unfortunately I can't find the discussion anymore.

Semantically a segment is a part of something that is divided. If the viewport is not divided, then there are no segments. When the device is not folded there are no division therefore no segments.

We don't want authors to write code against one segment because they should treat that case as the same as if there wasn't any split (meaning the device is used flat in the case of a foldable) or it's just a regular device. Furthermore, that one segment will return the same information as the viewport size bringing no useful information. We also don't want developer to feature check on this.

Finally, not returning a single segment match the CSS part of this API where the MQs do not resolve for a value of one segment. In other words, MQs values are always >= 2 for the segments.

@bramus
Copy link
Contributor Author

bramus commented Apr 16, 2025

We don't want authors to write code against one segment because they should treat that case as the same as if there wasn't any split (meaning the device is used flat in the case of a foldable) or it's just a regular device.

It’s not about writing code against 1 segment, but about consistency when enumerating the segments. We keep saying “1 segment” but that does not rhyme with null.

Finally, not returning a single segment match the CSS part of this API where the MQs do not resolve for a value of one segment.

Which MQ are you talking about? AFAIK there is only the device-posture media feature and some env-vars that people can use.


I asked on social media (bsky, masto) what developers think about this:

📊 Poll time: say there is an API to enumerate how many segments the viewport has. E.g. for a foldable phone the number would be 2 when the device is unfolded.

What would you expect this API to return when the foldable is closed, or when it’s a non-foldable device?

A. null
B. 1
C. ???

There was an overwhelming for answer B: 1 segment.

@darktears
Copy link
Contributor

darktears commented Apr 16, 2025

It’s not about writing code against 1 segment, but about consistency when enumerating the segments. We keep saying “1 segment” but that does not rhyme with null.

That's the thing, I don't want to talk about "1 segment" ever because it doesn't make sense conceptually IMHO.

Which MQ are you talking about? AFAIK there is only the device-posture media feature and some env-vars that people can use.

https://www.w3.org/TR/mediaqueries-5/#mf-horizontal-viewport-segments

I asked on social media (bsky, masto) what developers think about this:

📊 Poll time: say there is an API to enumerate how many segments the viewport has. E.g. for a foldable phone the number would be 2 when the device is unfolded.
What would you expect this API to return when the foldable is closed, or when it’s a non-foldable device?
A. null
B. 1
C. ???

There was an overwhelming for answer B: 1 segment.

Well, I guess I'll need to update the implementation and the spec.

@darktears
Copy link
Contributor

darktears commented Apr 16, 2025

In summary based on the various discussions on social websites we would be updating the specification to:

  • Return 1 segment when the device is used flat or any other non-foldable device.
  • The unique segment returned will be the same size as the viewport.

Other cases will behave the same as today, returning n segments depending on the device state and capabilities (one or multiple folds).

@astearns astearns added the Async Resolution: Proposed Candidate for auto-resolve with stated time limit label Apr 16, 2025
@darktears darktears self-assigned this Apr 16, 2025
@bramus
Copy link
Contributor Author

bramus commented Apr 19, 2025

Slight tweak of the first proposed resolution, to match the PR’d spec change: “Return an array with just the 1 segment when the device is used flat or any other non-foldable device.”

@astearns
Copy link
Member

The CSSWG will automatically accept this resolution one week from now if no objections are raised here. Anyone can add an emoji to this comment to express support. If you do not support this resolution, please add a new comment.

Proposed Resolution: Return an array with just one segment when the device is used flat or any other non-foldable device.

@astearns astearns added Async Resolution: Call For Consensus Resolution will be called after time limit expires and removed Async Resolution: Proposed Candidate for auto-resolve with stated time limit labels Apr 21, 2025
@astearns
Copy link
Member

RESOLVED: Return an array with just one segment when the device is used flat or any other non-foldable device.

@astearns astearns added Needs Edits Needs Testcase (WPT) and removed Async Resolution: Call For Consensus Resolution will be called after time limit expires labels Apr 28, 2025
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Apr 29, 2025
Per CSS resolution on w3c/csswg-drafts#11957,
always return an array of one segment when a foldable device is used
flat. This also applies to all non-foldable devices which means that
we do not increase the risk of fingerprinting.

This change also match the behavior of MQs (horizontal-viewport-segments for example).
They always match at a value of 1 (see RenderWidgetHostImpl::GetVisualProperties()).

This CL modifies the expected results of tests to reflect the new behavior.

There is no compat issue with this change as the feature is not yet
enabled by default.

Bug: 414430842

Change-Id: Id3cd0fc8ee47a68aadd3ded8d33624d41233f589
aarongable pushed a commit to chromium/chromium that referenced this issue Apr 29, 2025
Per CSS resolution on w3c/csswg-drafts#11957,
always return an array of one segment when a foldable device is used
flat. This also applies to all non-foldable devices which means that
we do not increase the risk of fingerprinting.

This change also match the behavior of MQs (horizontal-viewport-segments for example).
They always match at a value of 1 (see RenderWidgetHostImpl::GetVisualProperties()).

This CL modifies the expected results of tests to reflect the new behavior.

There is no compat issue with this change as the feature is not yet
enabled by default.

Bug: 414430842

Change-Id: Id3cd0fc8ee47a68aadd3ded8d33624d41233f589
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6469455
Reviewed-by: David Bokan <[email protected]>
Commit-Queue: Alexis Menard <[email protected]>
Reviewed-by: Alex N. Jose <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1453468}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Apr 29, 2025
Per CSS resolution on w3c/csswg-drafts#11957,
always return an array of one segment when a foldable device is used
flat. This also applies to all non-foldable devices which means that
we do not increase the risk of fingerprinting.

This change also match the behavior of MQs (horizontal-viewport-segments for example).
They always match at a value of 1 (see RenderWidgetHostImpl::GetVisualProperties()).

This CL modifies the expected results of tests to reflect the new behavior.

There is no compat issue with this change as the feature is not yet
enabled by default.

Bug: 414430842

Change-Id: Id3cd0fc8ee47a68aadd3ded8d33624d41233f589
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6469455
Reviewed-by: David Bokan <[email protected]>
Commit-Queue: Alexis Menard <[email protected]>
Reviewed-by: Alex N. Jose <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1453468}
chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue Apr 29, 2025
Per CSS resolution on w3c/csswg-drafts#11957,
always return an array of one segment when a foldable device is used
flat. This also applies to all non-foldable devices which means that
we do not increase the risk of fingerprinting.

This change also match the behavior of MQs (horizontal-viewport-segments for example).
They always match at a value of 1 (see RenderWidgetHostImpl::GetVisualProperties()).

This CL modifies the expected results of tests to reflect the new behavior.

There is no compat issue with this change as the feature is not yet
enabled by default.

Bug: 414430842

Change-Id: Id3cd0fc8ee47a68aadd3ded8d33624d41233f589
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6469455
Reviewed-by: David Bokan <[email protected]>
Commit-Queue: Alexis Menard <[email protected]>
Reviewed-by: Alex N. Jose <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1453468}
T3-M4 pushed a commit to bayandin/chromedriver that referenced this issue Apr 30, 2025
Per CSS resolution on w3c/csswg-drafts#11957,
always return an array of one segment when a foldable device is used
flat. This also applies to all non-foldable devices which means that
we do not increase the risk of fingerprinting.

This change also match the behavior of MQs (horizontal-viewport-segments for example).
They always match at a value of 1 (see RenderWidgetHostImpl::GetVisualProperties()).

This CL modifies the expected results of tests to reflect the new behavior.

There is no compat issue with this change as the feature is not yet
enabled by default.

Bug: 414430842

Change-Id: Id3cd0fc8ee47a68aadd3ded8d33624d41233f589
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/6469455
Reviewed-by: David Bokan <[email protected]>
Commit-Queue: Alexis Menard <[email protected]>
Reviewed-by: Alex N. Jose <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1453468}
@darktears
Copy link
Contributor

Spec change landed and WPT test added

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

3 participants