You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: _posts/2020-02-03-the-background-webcompat-debacle.markdown
+36-1Lines changed: 36 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -100,6 +100,36 @@ Serialization is the process of converting from a data structure (e.g. Rust stru
100
100
101
101
Whenever you ask the browser for state on styles, such as through the [HTMLElement.style](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/style) or [Window.getComputedStyle](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle) APIs, the value it returns to you is the result of the serialization of its data structures to a string.
102
102
103
+
It's important to note that how you input styles for an element may not be how they are later serialized back to you. In fact, this point is the crux of the issue we're exploring — the serialization of the `background` shorthand property differed from author's expectations based on previous browser behavior and the spec.
You might get back this (or something completely different, depending on your browser) post-serialization:
117
+
118
+
{% highlight javascript %}
119
+
const target = document.getElementById('target')
120
+
console.log(target.style['background'])
121
+
122
+
// Logs the following.
123
+
// Note the difference in order vs. what was specified above.
124
+
125
+
// url("https://bit.ly/") space round local
126
+
// 1px 2px / 3px 4px padding-box content-box,
127
+
// rgb(5, 6, 7) url("https://bit.ly/") space round local
128
+
// 1px 2px / 3px 4px padding-box content-box
129
+
{% endhighlight %}
130
+
131
+
The order in which properties are serialized could be very important. For example, perhaps you are writing a JavaScript framework that parses the serialized styles of HTML elements in order to compute some new ones. Different serializations in different browsers makes this much, much more difficult to do.
132
+
103
133
### So why was this change made?
104
134
105
135
Development of these specifications [happens on Github](https://github.com/w3c/csswg-drafts), so let's look at [the commit that introduced this revision](https://github.com/w3c/csswg-drafts/commit/02fe11230e02279b495e4c5931be6ed5bab61c5c):
@@ -125,7 +155,12 @@ Feel free to read the full conversation yourself — for the sake of brevity, he
125
155
</li>
126
156
<li>
127
157
<span class="non-bold">
128
-
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=743392">Authors complained</a> about this change in serialization, as tutorials had codified the CSS 2.1 serialization order.
158
+
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=743392">Authors complained</a> about this change in serialization, as tutorials had codified the CSS 2.1 serialization order (<code><background-color></code> first).
159
+
</span>
160
+
</li>
161
+
<li>
162
+
<span class="non-bold">
163
+
It is discovered Chrome's <code>background</code> shorthand serialization is "100% broken". While not made as explicit in the conversation, WebKit (Safari's browser engine) and Gecko (Firefox's browser engine) likely had, and may still have problems relative to the spec — more on that later.
0 commit comments