Intent to Ship: CSSPageRule to inherit from CSSGroupingRule

260 views
Skip to first unread message

Morten Stenshorne

unread,
May 8, 2024, 3:37:59 AMMay 8
to blink-dev

Contact emails

mste...@chromium.org

Explainer

None

Specification

https://drafts.csswg.org/cssom/#the-csspagerule-interface

Summary

Let CSSPageRule inherit from CSSGroupingRule instead of CSSRule. The spec [1] says that the CSSPageRule interface should inherit from CSSGroupingRule, but Blink inherits from CSSRule instead. In order to support @page margins (CSSMarginRule), CSSPageRule needs to support child rules. [1] https://drafts.csswg.org/cssom/#the-csspagerule-interface [2] https://drafts.csswg.org/css-page-3/#syntax-page-selector



Blink component

Blink>CSS

TAG review

None

TAG review status

Not applicable

Risks



Interoperability and Compatibility

Low risk. The one possible issue is if an author uses "instanceof CSSGroupingRule" or "instanceof CSSRule" with a page rule object and makes incorrect assumptions based on that. However, given that this is already shipping in Firefox (and also that in Firefox, even CSSStyleRule inherits from CSSGroupingRule, as the spec says - whereas Blink still doesn't), the risk should be very low.



Gecko: Shipped/Shipping (https://bugzilla.mozilla.org/show_bug.cgi?id=1868215)

WebKit: No signal

Web developers: No signals

Other signals:

WebView application risks

Does this intent deprecate or change behavior of existing APIs, such that it has potentially high risk for Android WebView-based applications?

None



Debuggability

None



Will this feature be supported on all six Blink platforms (Windows, Mac, Linux, ChromeOS, Android, and Android WebView)?

Yes

Is this feature fully tested by web-platform-tests?

Yes

Flag name on chrome://flags

None

Finch feature name

None

Non-finch justification

There's no way to make such a change behind a runtime feature flag, so this will just have to ship when the code change lands. In the worst case, it will have to be reverted.



Requires code in //chrome?

False

Tracking bug

https://issues.chromium.org/issues/324827379

Estimated milestones

Shipping on desktop126
Shipping on Android126


Anticipated spec changes

Open questions about a feature may be a source of future web compat or interop issues. Please list open issues (e.g. links to known github issues in the project for the feature specification) whose resolution may introduce web compat/interop risk (e.g., changing to naming or structure of the API in a non-backward-compatible way).

None

Link to entry on the Chrome Platform Status

https://chromestatus.com/feature/5218866421825536?gate=6703446991568896

This intent message was generated by Chrome Platform Status.

Mike Taylor

unread,
May 8, 2024, 11:18:21 AMMay 8
to Morten Stenshorne, blink-dev

On 5/8/24 3:37 AM, Morten Stenshorne wrote:

Interoperability and Compatibility

Low risk. The one possible issue is if an author uses "instanceof CSSGroupingRule" or "instanceof CSSRule" with a page rule object and makes incorrect assumptions based on that. However, given that this is already shipping in Firefox (and also that in Firefox, even CSSStyleRule inherits from CSSGroupingRule, as the spec says - whereas Blink still doesn't), the risk should be very low.

I agree the risk is likely very low, or contained to just a few sites/applications - have you done any investigation to try to find any problematic code examples that you mention (via GitHub search or HTTPArchive)?
Noting that the patch should ship to Firefox release channel (126) in about a week, per https://whattrainisitnow.com/calendar/.

WebKit: No signal
Can we request a signal? Or do we have any other indications about their intentions here?

Morten Stenshorne

unread,
May 9, 2024, 6:16:32 AMMay 9
to Mike Taylor, blink-dev
On Wed, 8 May 2024 at 17:18, Mike Taylor <mike...@chromium.org> wrote:

On 5/8/24 3:37 AM, Morten Stenshorne wrote:

Interoperability and Compatibility

Low risk. The one possible issue is if an author uses "instanceof CSSGroupingRule" or "instanceof CSSRule" with a page rule object and makes incorrect assumptions based on that. However, given that this is already shipping in Firefox (and also that in Firefox, even CSSStyleRule inherits from CSSGroupingRule, as the spec says - whereas Blink still doesn't), the risk should be very low.

I agree the risk is likely very low, or contained to just a few sites/applications - have you done any investigation to try to find any problematic code examples that you mention (via GitHub search or HTTPArchive)?

There's a use counter - https://chromestatus.com/metrics/feature/timeline/popularity/4862 - for CSSPageRule, but I'm not sure how useful it is, since it will count as long as someone e.g. iterates over the rules in a style sheet and there happens to be an @page rule in there. The use is currently at 0.07, but the number isn't that useful, apart from being an absolute worst-case number.

Here's a constructed problematic case if CSSPageRule suddenly inherits from CSSGroupingRule:

```
<style>
  @media screen {
    div {
      color: hotpink;
    }
  }
  @page {
    margin: 1in;
    @top-center {
      content: "Header";
    }
  }
</style>
<script>
  for (const rule of document.styleSheets[0].cssRules) {
    if (rule instanceof CSSGroupingRule) {
      // Aha! You're a media rule! (d'oh!)
      // ...
    }
  }
</script>
```

How likely is that, though?
 
Noting that the patch should ship to Firefox release channel (126) in about a week, per https://whattrainisitnow.com/calendar/.

Ah, right. Pretty recent change.

On that note, earlier (some time in 2023), Firefox changed CSSStyleRule to inherit from CSSGroupingRule - https://github.com/w3c/csswg-drafts/issues/8940#issuecomment-1747351690
That sounds like a much riskyisher change, but allegedly it went just fine.

WebKit: No signal
Can we request a signal? Or do we have any other indications about their intentions here?

Mike Taylor

unread,
May 13, 2024, 7:36:17 PMMay 13
to Morten Stenshorne, blink-dev

Hi Morten -

Appreciate the response. I spent some time looking at https://github.com/search?q=%22instanceof+CSSGroupingRule%22+language%3AJavaScript&type=code&l=JavaScript as well as "instanceof CSSRule" earlier, but didn't see anything immediately worrying (granted, it's hard to predict perfectly how the tooling-related scripts might handle sites in the wild that might ship the problematic patterns).

LGTM1 to ship.

Chris Harrelson

unread,
May 13, 2024, 7:49:52 PMMay 13
to Mike Taylor, Morten Stenshorne, blink-dev
LGTM2

--
You received this message because you are subscribed to the Google Groups "blink-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email to blink-dev+...@chromium.org.
To view this discussion on the web visit https://groups.google.com/a/chromium.org/d/msgid/blink-dev/ee67bf7d-78f9-4309-b831-00942ae69936%40chromium.org.

TAMURA, Kent

unread,
May 13, 2024, 9:20:27 PMMay 13
to Chris Harrelson, Mike Taylor, Morten Stenshorne, blink-dev
LGTM3




--
TAMURA Kent
Software Engineer, Google


Reply all
Reply to author
Forward
0 new messages