Contact emails:
Emilio Cobos Álvarez (
emi...@chromium.org,
emi...@mozilla.com)
Spec:
https://drafts.csswg.org/cssom/#set-a-css-declaration
Summary:
We change the behavior of the CSSOM APIs when the property to set is
already specified to append to the declaration block instead of
replacing the slot.
For example, if you had:
<div id="test" style="color: red; padding: 10px;"></div>
And you did:
test.style.color = "green";
Before the change you'd get:
<div id="test" style="color: green; padding: 10px;"></div>
And afterwards:
<div id="test" style="padding: 10px; color: green;"></div>
Motivation:
The reasoning for this is that the current behavior interacts very
poorly with logical properties and mutation events / mutation observers
of the style attribute. There's a lengthy discussion and CSSWG
resolution in:
https://github.com/w3c/csswg-drafts/issues/1898
As for the motivation for me submitting this patch to Blink, see below.
Risks:
Interoperability and Compatibility:
Regarding support from other vendors, this was resolved in a CSSWG F2F
with members from all vendors in the room actively participating in the
discussion, so I'd say all vendors publicly support this.
Firefox implemented this change already in:
https://bugzilla.mozilla.org/show_bug.cgi?id=1415330
Which is currently in Firefox Beta.
This change has some risk though, and one broken website was reported in
Firefox because of this:
https://bugzilla.mozilla.org/show_bug.cgi?id=1460295
That website mutates the style attribute in a DOMSubtreeModified event
callback, triggering itself more mutations that before (contrary to the
spec) weren't fired.
This is my main motivation for submitting the change. I fear that Gecko
would need to back out this change or cope with a few webcompat bugs if
other engines like Blink don't adopt the spec resolution soon as well,
and I don't see any other way to make the interactions between logical
properties and CSSOM sound.
Note, though, that that particular website wouldn't be broken on Blink /
WebKit anyways because Blink doesn't support the DOMAttrModified event /
doesn't fire DOMSubtreeModified when an attribute changes (only when
it's added / removed), as it can be seen in
https://bug1460295.bmoattachments.org/attachment.cgi?id=8975780. I'm
trying to sort out what the right thing to do there is on Gecko's side.
My intention is to submit a WebKit patch too if this intent goes well.
In general I think that the risk is low over-all, and we haven't heard
of more breakage than that particular case, which wouldn't affect Blink.
But I think it was worth to point that out.
Ergonomics:
This is an existing and commonly used API, and its behavior is closer to
what authors would expect in cases where logical properties are involved.
Debuggability:
No changes in devtools or similar should be needed.
Will this feature be supported on all six Blink platforms (Windows, Mac,
Linux, Chrome OS, Android, and Android WebView)?
Yes
Is this feature fully tested by web-platform-tests?
Yes, tests for this spec and implementation change were added in
https://github.com/w3c/web-platform-tests/pull/10354.
Other related tests were added in
https://github.com/w3c/web-platform-tests/pull/10429.
Requesting approval to ship?
Yes
Thanks for reading,
-- Emilio