Bug 271001 - CSSOM serialization unexpectedly expands some shorthand properties
Summary: CSSOM serialization unexpectedly expands some shorthand properties
Status: RESOLVED DUPLICATE of bug 247852
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar
Depends on:
Blocks:
 
Reported: 2024-03-14 13:23 PDT by Qianlang Chen
Modified: 2024-04-07 17:35 PDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Qianlang Chen 2024-03-14 13:23:08 PDT
(See also https://webkit.org/b/75538 and https://webkit.org/b/73002, where this bug has been reported and a fix was attempted.)

The return values of `CSSRule.cssText` and `CSSStyleDeclaration.cssText` getters expand some shorthand CSS properties, specifically font-related shorthands like `font` or `font-variant`.

To reproduce, run this code in Safari inspector's console:
    s = new CSSStyleSheet(); 
    s.replaceSync('body { font: 12px serif; }'); 
    console.log(s.cssRules[0].cssText);

Observe that the output contains all the expanded longhand properties:
    body { font-style: normal; font-variant-caps: normal; font-weight: normal; font-stretch: normal; font-size: 12px; line-height: normal; font-family: serif; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-variant-emoji: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal; }

The expected output should just be
    body { font: 12px serif; }

The issue should be associated with how WebKit serializes a CSS declaration. The specs (https://drafts.csswg.org/cssom-1/#serialize-a-css-declaration-block), albeit very hard to read, suggest that shorthand properties should not be expanded and replaced with their longhand equivalents.
Comment 1 Radar WebKit Bug Importer 2024-03-14 13:23:40 PDT
<rdar://problem/124635151>
Comment 2 Karl Dubost 2024-03-25 14:20:53 PDT
With 
  data:text/html,<div id="target" style="font: 12px serif">foo</div>

and 
  const target = document.querySelector("#target");
  target.style.cssText;

On Firefox, Chrome
cssText: "font: 12px serif;" 

On Safari
"font-style: normal; font-variant-caps: normal; font-weight: normal; font-stretch: normal; font-size: 12px; line-height: normal; font-family: serif; font-size-adjust: none; font-kerning: auto; font-variant-alternates: normal; font-variant-ligatures: normal; font-variant-numeric: normal; font-variant-east-asian: normal; font-variant-position: normal; font-variant-emoji: normal; font-feature-settings: normal; font-optical-sizing: auto; font-variation-settings: normal;"
Comment 3 Karl Dubost 2024-03-25 14:25:22 PDT
I wonder if there's a WPT already covering this.
Comment 4 Ahmad Saleem 2024-04-05 14:55:28 PDT
Might be dupe of bug 247852?
Comment 5 Qianlang Chen 2024-04-05 14:56:44 PDT
(In reply to Ahmad Saleem from comment #4)
> Might be dupe of bug 247852?

Oooh, looks like it!
Comment 6 Karl Dubost 2024-04-07 17:35:31 PDT

*** This bug has been marked as a duplicate of bug 247852 ***