Bug 185953 - cssText serialization doesn't contain properties with "initial" values
Summary: cssText serialization doesn't contain properties with "initial" values
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: CSS (show other bugs)
Version: Safari 11
Hardware: Mac macOS 10.13
: P2 Normal
Assignee: Nobody
URL:
Keywords: BrowserCompat, InRadar, Regression
: 245104 245105 248442 (view as bug list)
Depends on: 242775 248913
Blocks: 81737 190496
  Show dependency treegraph
 
Reported: 2018-05-24 11:56 PDT by Ben Dean
Modified: 2023-02-09 12:42 PST (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ben Dean 2018-05-24 11:56:09 PDT
This happens for both CSSStyleDeclaration.cssText and CSSRule.cssText.

```
var styleEl = document.createElement('style');
styleEl.textContent = 'body { width: initial; }'
document.head.appendChild(styleEl);

console.log(styleEl.sheet.cssRules[0].cssText);
```

Expected:
> "body { width: initial; }"

Got:
> "body { }"

You can try it here at https://jsfiddle.net/vu434w60/

Thanks!
Comment 1 Oriol Brufau 2018-09-13 10:13:19 PDT
The cause seems that StyleProperties::asText() in Source/WebCore/css/StyleProperties.cpp has this code:

        if (propertyID != CSSPropertyCustom && value == "initial" && !CSSProperty::isInheritedProperty(propertyID))
            continue;

This was added in https://bugs.webkit.org/show_bug.cgi?id=81737

But it can't simply be removed, the logic to handle serialization of shorthands and longhands needs to be refactored.
Comment 2 Radar WebKit Bug Importer 2022-07-15 13:43:11 PDT
<rdar://problem/97091857>
Comment 3 Oriol Brufau 2022-09-23 06:55:32 PDT
*** Bug 245105 has been marked as a duplicate of this bug. ***
Comment 4 Oriol Brufau 2022-11-28 17:27:41 PST
*** Bug 248442 has been marked as a duplicate of this bug. ***
Comment 5 Oriol Brufau 2022-12-07 08:30:08 PST
Testcase in comment 0 works well now.
Bug 242775 made it so that only implicit 'initial' values would be skipped.
For example, this is still wrong:

    var {style} = document.createElement("div");
    style.container = "foo";
    style.removeProperty("container-name");
    style.cssText;

Ideally this should be "container-type: normal;", but given that style.containerType is "initial" in WebKit, then it should be "container-type: initial;". However, it's just empty string.

This remaining problem should be fixed by removing implicit flags (bug 248383).
Comment 6 Oriol Brufau 2023-02-09 12:26:03 PST
The code skipping implicit initial values was removed in bug 248913.
Comment 7 Oriol Brufau 2023-02-09 12:42:22 PST
*** Bug 245104 has been marked as a duplicate of this bug. ***