[css-cascade-5] Reconsider placement of unlayered styles, for better progressive enhancement? · Issue #6284 · w3c/csswg-drafts (original) (raw)

Comments

@mirisuzanne

In the spec for Cascade Layers we define default unlayered styles as being at the top of the normal layer stack, and the bottom of the !important layers. Any explicit layers are added below the normal unlayered styles, with layered important styles above unlayered important styles.

I'm not sure this matches either developer instinct, or the best path for authors to start integrating cascade layers as a progressive enhancement.

When I think about serving a simpler set of styles to older browsers, I would want those browsers to get the most broad defaults, along with anything most important in those defaults. But with unlayered styles at the top of the normal stack, authors are instead encouraged to move their most broadly-applied , lowest-priority styles (resets, global typography, etc) into layers first -- hiding them from old browsers. If default styles were at the bottom of the normal layers, authors could instead begin adding layers for more narrowly targeted styles.

So I'm proposing we change the way unlayered styles stack:

@mirisuzanne mirisuzanne changed the title[css-cascade-5] Reconsider placement of unlayered styles, in relation to better progressive enhancement? [css-cascade-5] Reconsider placement of unlayered styles, for better progressive enhancement?

May 11, 2021

@tabatkins

I don't think I had too much of an opinion on whether unlayered styles were above or below the other layers. Your argument seems pretty reasonable to me.

@jensimmons

Honestly, I can imagine usecases where it'd be best for unlayered styles to have more specificity, and usecases where it'd be best for less specificity. Especially when thinking about transitioning from existing projects; considering progressive enhancement needs; how devs might slowly detangle a large preexisting project by moving code in new layers over time; and putting 3rd party code in a layer while keeping custom code unlayered.

Would it be possible to allow Authors to set for themselves where in the cascade the "unlayered layer" resides? Maybe they even want to sandwich it in-between. A mechanism that's part of however they define the named layers & determine which layer is "first" & "second", etc.

There will need to be a default, in case they don't set this. And perhaps the default should switch as described above. But I'm not sure the default will work for all usecases.

@css-meeting-bot

The CSS Working Group just discussed [css-cascade-5] Reconsider placement of unlayered styles, for better progressive enhancement?, and agreed to the following:

@mirisuzanne

fantasai added a commit that referenced this issue

Oct 4, 2021

@fantasai

@FremyCompany

FWIW now that I saw an example of this in practice, I am under the impression that this reversal of order doesn't serve the use cases that layers were supposed to address.

The main use cases I can see for layers are resets, frameworks, and framework themes. Having these styles above the site's styles just doesn't work.

See the example at the start of this thread, it just doesn't make any sense to me:
https://twitter.com/fremycompany/status/1445126893037031425?s=21

I think it would be worth having a redo of this conversation in the light of this example to confirm this is still a decision the group is confortable about.

In my opinion, if you start using layers, the only type of polyfill that will work to support older browsers will be to just wrap every rule in :where() to nuke its priority and rewrite the files so that rule order match the priority order after layers have been taken into consideration.

I don't think one can simply decide some styles just don't get received by a supported browser, whether that style is a reset or a specific style shouldn't matter much, it is necessary all the same. So the reasoning at the start of the thread doesn't speak to me.

But this is just my opinion of course, I just want to make sure this gets a review before implementations ship.

@mirisuzanne

Agenda+ to review this. I wonder if we can add it to the special call tomorrow? I know that time might not be a great time for you @FremyCompany, but I think there might be some urgency since three browser engines support layers behind a flag already.

@FremyCompany

Additional comment here: #6323 (comment)

Another approach I have been thinking about is to have two lists independently, all layers that must be above the unlayered styles, and all who need to be below. [...]

@css-meeting-bot

The CSS Working Group just discussed Reconsider placement of unlayered styles, for better progressive enhancement?, and agreed to the following:

webkit-commit-queue pushed a commit to WebKit/WebKit that referenced this issue

Oct 7, 2021

@anttijk

https://bugs.webkit.org/show_bug.cgi?id=231342

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

Update from the WPT repo.

Source/WebCore:

Update the implementation to match the resolution for w3c/csswg-drafts#6284.

Return std::numeric_limits::max() for unlayered rules.

(WebCore::Style::RuleSet::cascadeLayerOrderForIdentifier const): Deleted. (WebCore::Style::RuleSet::cascadeLayerOrderFor const): Deleted.

Also update naming order->priority to better match the spec text.

Canonical link: https://commits.webkit.org/242643@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@283718 268f45cc-cd09-0410-ab3c-d52691b4dbfc

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue

Oct 8, 2021

@xiaochengh @chromium-wpt-export-bot

This patch follows from a recent CSSWG resolution [1] that puts the default layer at the highest priority, and a subsequent spec edit [2] that changed the layer ordering from the preorder of the layer tree to the postorder.

[1] w3c/csswg-drafts#6284 (comment) [2] w3c/csswg-drafts@a6fc16e

Fixed: 1257936 Change-Id: I899de8c8a921b0535296957ee1b0cca1f60a8c61

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue

Oct 9, 2021

@xiaochengh @chromium-wpt-export-bot

This patch follows from a recent CSSWG resolution [1] that puts the default layer at the highest priority, and a subsequent spec edit [2] that changed the layer ordering from the preorder of the layer tree to the postorder.

Most test changes just reflect this spec change. In some WPT tests, rule ordering is swapping so that the winning rule will appear first, so that we can verify layer is working.

external/wpt/css/css-cascade/presentational-hints-cascade.html is moved from the stable test suite to a new disable-custom-element-default-style virtual test suite because this is the flag that actually makes the test result different on test and stable builds. We need to disable this flag while keeping cascade layers enabled to test the new test case in the file.

[1] w3c/csswg-drafts#6284 (comment) [2] w3c/csswg-drafts@a6fc16e

Fixed: 1257936 Change-Id: I899de8c8a921b0535296957ee1b0cca1f60a8c61

bertogg pushed a commit to Igalia/webkit that referenced this issue

Oct 9, 2021

https://bugs.webkit.org/show_bug.cgi?id=231342

Reviewed by Simon Fraser.

LayoutTests/imported/w3c:

Update from the WPT repo.

Source/WebCore:

Update the implementation to match the resolution for w3c/csswg-drafts#6284.

Return std::numeric_limits::max() for unlayered rules.

(WebCore::Style::RuleSet::cascadeLayerOrderForIdentifier const): Deleted. (WebCore::Style::RuleSet::cascadeLayerOrderFor const): Deleted.

Also update naming order->priority to better match the spec text.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@283718 268f45cc-cd09-0410-ab3c-d52691b4dbfc

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue

Oct 12, 2021

@xiaochengh @chromium-wpt-export-bot

This patch follows from a recent CSSWG resolution [1] that puts the default layer at the highest priority, and a subsequent spec edit [2] that changed the layer ordering from the preorder of the layer tree to the postorder.

Most test changes just reflect this spec change. In some WPT tests, rule ordering is swapping so that the winning rule will appear first, so that we can verify layer is working.

external/wpt/css/css-cascade/presentational-hints-cascade.html is moved from the stable test suite to a new disable-custom-element-default-style virtual test suite because this is the flag that actually makes the test result different on test and stable builds. We need to disable this flag while keeping cascade layers enabled to test the new test case in the file.

[1] w3c/csswg-drafts#6284 (comment) [2] w3c/csswg-drafts@a6fc16e

Fixed: 1257936 Change-Id: I899de8c8a921b0535296957ee1b0cca1f60a8c61 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3214603 Reviewed-by: Anders Hartvoll Ruud andruud@chromium.org Reviewed-by: Xianzhu Wang wangxianzhu@chromium.org Commit-Queue: Xiaocheng Hu xiaochengh@chromium.org Cr-Commit-Position: refs/heads/main@{#930689}

chromium-wpt-export-bot pushed a commit to web-platform-tests/wpt that referenced this issue

Oct 12, 2021

@xiaochengh @chromium-wpt-export-bot

This patch follows from a recent CSSWG resolution [1] that puts the default layer at the highest priority, and a subsequent spec edit [2] that changed the layer ordering from the preorder of the layer tree to the postorder.

Most test changes just reflect this spec change. In some WPT tests, rule ordering is swapping so that the winning rule will appear first, so that we can verify layer is working.

external/wpt/css/css-cascade/presentational-hints-cascade.html is moved from the stable test suite to a new disable-custom-element-default-style virtual test suite because this is the flag that actually makes the test result different on test and stable builds. We need to disable this flag while keeping cascade layers enabled to test the new test case in the file.

[1] w3c/csswg-drafts#6284 (comment) [2] w3c/csswg-drafts@a6fc16e

Fixed: 1257936 Change-Id: I899de8c8a921b0535296957ee1b0cca1f60a8c61 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3214603 Reviewed-by: Anders Hartvoll Ruud andruud@chromium.org Reviewed-by: Xianzhu Wang wangxianzhu@chromium.org Commit-Queue: Xiaocheng Hu xiaochengh@chromium.org Cr-Commit-Position: refs/heads/main@{#930689}

pull bot pushed a commit to Yannic/chromium that referenced this issue

Oct 13, 2021

@xiaochengh

This patch follows from a recent CSSWG resolution [1] that puts the default layer at the highest priority, and a subsequent spec edit [2] that changed the layer ordering from the preorder of the layer tree to the postorder.

Most test changes just reflect this spec change. In some WPT tests, rule ordering is swapping so that the winning rule will appear first, so that we can verify layer is working.

external/wpt/css/css-cascade/presentational-hints-cascade.html is moved from the stable test suite to a new disable-custom-element-default-style virtual test suite because this is the flag that actually makes the test result different on test and stable builds. We need to disable this flag while keeping cascade layers enabled to test the new test case in the file.

[1] w3c/csswg-drafts#6284 (comment) [2] w3c/csswg-drafts@a6fc16e

Fixed: 1257936 Change-Id: I899de8c8a921b0535296957ee1b0cca1f60a8c61 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3214603 Reviewed-by: Anders Hartvoll Ruud andruud@chromium.org Reviewed-by: Xianzhu Wang wangxianzhu@chromium.org Commit-Queue: Xiaocheng Hu xiaochengh@chromium.org Cr-Commit-Position: refs/heads/main@{#930689}

moz-v2v-gh pushed a commit to mozilla/gecko-dev that referenced this issue

Oct 14, 2021

@xiaochengh @moz-wptsync-bot

…r to postorder, a=testonly

Automatic update from web-platform-tests [@layer] Change layer order from preorder to postorder

This patch follows from a recent CSSWG resolution [1] that puts the default layer at the highest priority, and a subsequent spec edit [2] that changed the layer ordering from the preorder of the layer tree to the postorder.

Most test changes just reflect this spec change. In some WPT tests, rule ordering is swapping so that the winning rule will appear first, so that we can verify layer is working.

external/wpt/css/css-cascade/presentational-hints-cascade.html is moved from the stable test suite to a new disable-custom-element-default-style virtual test suite because this is the flag that actually makes the test result different on test and stable builds. We need to disable this flag while keeping cascade layers enabled to test the new test case in the file.

[1] w3c/csswg-drafts#6284 (comment) [2] w3c/csswg-drafts@a6fc16e

Fixed: 1257936 Change-Id: I899de8c8a921b0535296957ee1b0cca1f60a8c61 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3214603 Reviewed-by: Anders Hartvoll Ruud andruud@chromium.org Reviewed-by: Xianzhu Wang wangxianzhu@chromium.org Commit-Queue: Xiaocheng Hu xiaochengh@chromium.org Cr-Commit-Position: refs/heads/main@{#930689}

--

wpt-commits: fd7a9e9a139e01cd5017b57b8d3123d3a9a1a7bb wpt-pr: 31169

jamienicol pushed a commit to jamienicol/gecko that referenced this issue

Oct 14, 2021

@xiaochengh @moz-wptsync-bot

…r to postorder, a=testonly

Automatic update from web-platform-tests [@layer] Change layer order from preorder to postorder

This patch follows from a recent CSSWG resolution [1] that puts the default layer at the highest priority, and a subsequent spec edit [2] that changed the layer ordering from the preorder of the layer tree to the postorder.

Most test changes just reflect this spec change. In some WPT tests, rule ordering is swapping so that the winning rule will appear first, so that we can verify layer is working.

external/wpt/css/css-cascade/presentational-hints-cascade.html is moved from the stable test suite to a new disable-custom-element-default-style virtual test suite because this is the flag that actually makes the test result different on test and stable builds. We need to disable this flag while keeping cascade layers enabled to test the new test case in the file.

[1] w3c/csswg-drafts#6284 (comment) [2] w3c/csswg-drafts@a6fc16e

Fixed: 1257936 Change-Id: I899de8c8a921b0535296957ee1b0cca1f60a8c61 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3214603 Reviewed-by: Anders Hartvoll Ruud andruud@chromium.org Reviewed-by: Xianzhu Wang wangxianzhu@chromium.org Commit-Queue: Xiaocheng Hu xiaochengh@chromium.org Cr-Commit-Position: refs/heads/main@{#930689}

--

wpt-commits: fd7a9e9a139e01cd5017b57b8d3123d3a9a1a7bb wpt-pr: 31169

Gabisampaio pushed a commit to Gabisampaio/wpt that referenced this issue

Nov 18, 2021

@xiaochengh @Gabisampaio

This patch follows from a recent CSSWG resolution [1] that puts the default layer at the highest priority, and a subsequent spec edit [2] that changed the layer ordering from the preorder of the layer tree to the postorder.

Most test changes just reflect this spec change. In some WPT tests, rule ordering is swapping so that the winning rule will appear first, so that we can verify layer is working.

external/wpt/css/css-cascade/presentational-hints-cascade.html is moved from the stable test suite to a new disable-custom-element-default-style virtual test suite because this is the flag that actually makes the test result different on test and stable builds. We need to disable this flag while keeping cascade layers enabled to test the new test case in the file.

[1] w3c/csswg-drafts#6284 (comment) [2] w3c/csswg-drafts@a6fc16e

Fixed: 1257936 Change-Id: I899de8c8a921b0535296957ee1b0cca1f60a8c61 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3214603 Reviewed-by: Anders Hartvoll Ruud andruud@chromium.org Reviewed-by: Xianzhu Wang wangxianzhu@chromium.org Commit-Queue: Xiaocheng Hu xiaochengh@chromium.org Cr-Commit-Position: refs/heads/main@{#930689}

@jridgewell

I represent the AMP library, and wanted to chime in that we believe the decision to revert this was the correct choice. AMP wants to provide a set of default styles as a framework that end users can then add their own styles on top of. We've had issues in past where changing a framework selector in anyway causes it to become more specific than the end user's selector, and now our default styles are overriding their intended styles.

We're looking to use @layer to solve this, so that all of our styles are truly defaults and any unlayered end user styles will override our @layer styles. We fully expect our end users to continue to write unlayered styles just out of habit. Now we can be free to make our @layer selectors extremely specific without worrying that we'll win over the end user's selector.

@layer AMP { /* We should be able to change this selector to any specificity / amp-foo p { / This default style should be easy to override */ color: red; font-size: 100px; } }

/* End users will write unlayered out of habit / p { / This should win, even though p is less specific than amp-foo p */ color: green; }

buondevid added a commit to buondevid/content that referenced this issue

Jan 14, 2022

@buondevid

The spec changed 3 months ago, time to update your docs :) w3c/csswg-drafts#6284 (comment)

The docs now should be correct at least, I'm not sure whether it's the better formulation as English is not my mother tongue.

Extra: the last LiveSample looks broken, no styling is applied at the moment.

mjfroman pushed a commit to mjfroman/moz-libwebrtc-third-party that referenced this issue

Oct 14, 2022

@xiaochengh @copybara-github

This patch follows from a recent CSSWG resolution [1] that puts the default layer at the highest priority, and a subsequent spec edit [2] that changed the layer ordering from the preorder of the layer tree to the postorder.

Most test changes just reflect this spec change. In some WPT tests, rule ordering is swapping so that the winning rule will appear first, so that we can verify layer is working.

external/wpt/css/css-cascade/presentational-hints-cascade.html is moved from the stable test suite to a new disable-custom-element-default-style virtual test suite because this is the flag that actually makes the test result different on test and stable builds. We need to disable this flag while keeping cascade layers enabled to test the new test case in the file.

[1] w3c/csswg-drafts#6284 (comment) [2] w3c/csswg-drafts@a6fc16e

Fixed: 1257936 Change-Id: I899de8c8a921b0535296957ee1b0cca1f60a8c61 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/3214603 Reviewed-by: Anders Hartvoll Ruud andruud@chromium.org Reviewed-by: Xianzhu Wang wangxianzhu@chromium.org Commit-Queue: Xiaocheng Hu xiaochengh@chromium.org Cr-Commit-Position: refs/heads/main@{#930689} NOKEYCHECK=True GitOrigin-RevId: 51f228d925be264a6d1df4f90ca36c73a052d010

@andremarcondesteixeira

@mcareydsgn

@mirisuzanne

We cannot reverse this, it's already widely used. But we knew it was a tradeoff between short-term and long-term goals. The fact that it's frustrating during this transition period is not a surprise, it's exactly the tradeoff we decided to make in favor of the long-term design of the feature.

@mirisuzanne

The primary deciding factor (for anyone who hasn't been part of the conversation from the start) was this:

Because it's possible to add and nest layers, but not possible to remove or un-nest layers, this is the only solution that gives site authors long-term control over the entire system. Does that mean it's perfect? No. But the alternative seemed (and still seems to me) worse. We made a tradeoff, as we often do.

We can't change that decision. But we can add to it. Documenting the pain-points that remain, and looking for ways to address them is what we're here for! I think the main one is to give authors some ability to place layers above the unlayered styles. We have an active thread for that. It's a complex problem, but I think we can get to something that works.

I think tool-makers (like WordPress) should also think of ways to let site authors put their tool-provided styles into layers. That doesn't have to be WP adopting layers for everyone, but providing a way that authors can opt-into layering WP styles would be great. (WP is just one example of many)