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
+29-23Lines changed: 29 additions & 23 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,6 +4,7 @@ title: "The `background` debacle — a case study on web compatibility"
4
4
date: 2020-02-03 12:42:53
5
5
categories: posts
6
6
description: A case study on web compatibility featuring the serialization of the `background` CSS shorthand property. Learn about the CSS standards process and web platform tests (WPTs) along the way.
7
+
published: false
7
8
---
8
9
9
10
{: .no_toc}
@@ -19,12 +20,12 @@ When browsing the [CSS Backgrounds 3 spec](https://www.w3.org/TR/2017/CR-css-bac
19
20
<ahref="/assets/img/background_serialization/bg_serialization_change.png"></a>
20
21
{:refdef}
21
22
22
-
Clicking into the `final-bg-layer` hyperlink, we discover this revision changed the serialization order of the `background` shorthand property:
23
+
Clicking into the <code><final-bg-layer></code> hyperlink, we discover this revision changed the serialization order of the `background` shorthand property:
23
24
24
25
{:refdef: style="text-align: center;"}
25
26
<ahref="/assets/img/background_serialization/bg_serialization_change.png"></a>
26
27
{:refdef}
27
-
<divstyle="margin-top: -20px; margin-bottom: 10px; text-align: center; font-style: italic; font-size: .85rem">The <spanstyle="font-style: normal"><code>#</code></span> next to <spanstyle="font-style: italic;"><code>bg-layer</code></span> means "0 or more" non-final background layers</div>
28
+
<divstyle="margin-top: -20px; margin-bottom: 10px; text-align: center; font-style: italic; font-size: .85rem">The <spanstyle="font-style: normal"><code>#</code></span> next to <spanstyle="font-style: italic;"><code><bg-layer></code></span> means "0 or more" non-final background layers</div>
28
29
29
30
This intrigued me. Why do authors expect the color to be first? Why does it make less sense for the color to be first? How was the decision made to make this change to the specification?
30
31
@@ -83,17 +84,23 @@ In summary: CSS syntax is standardized by the [CSSWG (CSS working group)](https:
83
84
84
85
The above is largely a summary of [this article](https://css-tricks.com/css-standards-process/), so head there if you're looking for more detail.
85
86
86
-
### Back to business
87
+
### Authors? Serialization?
87
88
88
-
Let's get back to our original goal: digging into [this revision](https://www.w3.org/TR/2017/CR-css-backgrounds-3-20171017/#changes-2014-09) in the CSS Backgrounds 3 specification:
89
+
Before we continue, allow me to clarify some terms you might not be familiar with.
89
90
90
-
> Moved <‘background-color’> component of <final-bg-layer> to the front for serialization because some authors seem to expect this even though it makes less sense?
91
+
> Moved <background-color> component of <final-bg-layer> to the front for serialization because some authors seem to expect this even though it makes less sense?
91
92
92
-
In the context of CSS specifications, "authors" are the authors of webpages — web developers. You may also see the terminology "implementor" — these are the people implementing the specification, so browser (also known as _user agent_) developers.
93
+
In the context of CSS specifications, "authors" are the authors of webpages — web developers. You may also see the terminology "implementor" — these are the people implementing the specification, so browser (which is also known as a_user agent_) developers.
93
94
94
-
Serialization is the process of converting an author-given value into something with semantic value to a user agent[^1]. That's why the order is important — if browsers expect the first value in a list of values to be a <code>background-color</code> but instead get something else, such as a <code>bg-image</code>, the value for the property won't get serialized as the author might expect (if at all).
95
+
Serialization is the process of converting from a data structure (e.g. Rust struct, C++ class) representation of a CSS object to a string representation of that CSS object. To see this more concretely, check out [this portion of the CSSOM (CSS Object Model) spec](https://drafts.csswg.org/cssom/#serializing-css-values) that details step-by-step how to serialize various CSS values and components. Here's an excerpt showing serialization of a ratio value:
95
96
96
-
### Why was this change made?
97
+
{:refdef: style="text-align: center;"}
98
+
<ahref="/assets/img/background_serialization/serialize_ratio_component.png"></a>
99
+
{:refdef}
100
+
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
+
103
+
### So why was this change made?
97
104
98
105
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):
99
106
@@ -108,24 +115,24 @@ Feel free to read the full conversation yourself — for the sake of brevity, he
108
115
<olclass="bold slightly-spaced-list">
109
116
<li>
110
117
<span class="non-bold">
111
-
The <a href="https://www.w3.org/TR/CSS21/colors.html#background-properties">CSS 2.1 background spec</a> placed the <code>background-color</code> first in the value list.
118
+
The <a href="https://www.w3.org/TR/CSS21/colors.html#background-properties">CSS 2.1 background spec</a> placed the <code><background-color></code> first in the value list.
112
119
</span>
113
120
</li>
114
121
<li>
115
122
<span class="non-bold">
116
-
For CSS3, the <code>background-color</code> was moved to the end of the final background layer because it is painted underneath all the other components of this layer (e.g. the background image and all its modifiers).
123
+
For CSS3, the <code><background-color></code> was moved to the end of the final background layer because it is painted underneath all the other components of this layer (e.g. the background image and all its modifiers).
117
124
</span>
118
125
</li>
119
126
<li>
120
127
<span class="non-bold">
121
-
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=743392">Authors complained</a> about this change in serialization, as tutorials had codified CSS 2.1 serialization order.
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.
122
129
</span>
123
130
</li>
124
131
</ol>
125
132
126
133
### But wait, there's more!
127
134
128
-
This 2015 spec revision was not the end of the confusion surrounding `background` serialization — the topic [came back up again](https://github.com/w3c/csswg-drafts/issues/418) in 2016:
135
+
This 2015 spec revision was not the end of the confusion surrounding `background` serialization — the topic [came back up again](https://github.com/w3c/csswg-drafts/issues/418)as an issue in the CSSWG repository in 2016:
129
136
130
137
{:refdef: style="text-align: center;"}
131
138
<ahref="/assets/img/background_serialization/cssom_define_ser.png"></a>
@@ -135,28 +142,27 @@ This 2015 spec revision was not the end of the confusion surrounding `background
135
142
<ahref="/assets/img/background_serialization/serialization_questions.png"></a>
136
143
{:refdef}
137
144
138
-
And roughly two years after this, [it was noted](https://github.com/w3c/csswg-drafts/issues/418#issuecomment-380951618) that this inconsistency across browsers still existed.
145
+
And roughly two years after this issue was opened, [it was noted](https://github.com/w3c/csswg-drafts/issues/418#issuecomment-380951618) that this inconsistency across browsers still existed.
146
+
147
+
TODO: Wait, they're all wrong in lots of different ways! Write about this.
139
148
140
149
### Web platform tests: the ultimate equalizer
141
150
142
-
There is a largely happy ending to a story, and it comes thanks to something called a _web platform test_ (WPT). Quoting the [WPT project readme](https://github.com/web-platform-tests/wpt#the-web-platform-tests-project):
151
+
There is a largely happy ending to this story, and it comes thanks to something called a _web platform test_ (WPT). Quoting the [WPT project readme](https://github.com/web-platform-tests/wpt#the-web-platform-tests-project):
143
152
144
153
> The web-platform-tests project is a cross-browser test suite for the Web-platform stack. Writing tests in a way that allows them to be run in all browsers gives browser projects confidence that they are shipping software that is compatible with other implementations, and that later implementations will be compatible with their implementations.
145
154
146
-
Most browsers automatically sync these tests to their own repositories, and use them to help prevent any set of changes from accidentally regressing web-compatibility.
155
+
Most browsers automatically sync these tests to their own repositories, and use them to help prevent any set of changes from accidentally regressing web-compatibility. At the time of this post, there are a whopping 41,492 WPTs, each of which made up of one or more subtests, for a grand total of _1,711,211 subtests_. That's a lot!
156
+
157
+
The `web-platform-tests` group also maintains a website called [wpt.fyi](https://wpt.fyi/results/?label=experimental&label=master&aligned), which provides a dashboard to view the results of any and all WPTs for the included browsers.
147
158
148
-
As you might now be guessing, [a WPT was created](https://github.com/web-platform-tests/wpt/pull/10462/files) to account for all the various ways the `background` shorthand property may be ordered in the wild. With this test in place, browsers can more easily align on the acceptance of various different `background` serializations, or at the very least make a lack of compatibility obvious in test failure.
As you might now be guessing, [a WPT was created](https://github.com/web-platform-tests/wpt/pull/10462/files) to account for all the various ways the `background` shorthand property may be serialized. With this test in place, browsers can more easily align on the acceptance of various different `background` serializations, or at the very least make a lack of compatibility obvious in test failure.
149
162
150
163
### Summary
151
164
152
165
In summary, web compatibility is hard. Thank your local browser developer when you next get a chance :)
153
166
154
167
If you have any questions, comments, or corrections, feel free to [open up an issue](https://github.com/twilco/twilco.github.io/issues) or leave a comment below via [utterances](https://github.com/utterance/utterances).
155
168
156
-
<br />
157
-
158
-
---
159
-
160
-
<br />
161
-
162
-
[^1]: Reading various other specifications, serialization also seems to refer to the opposite process of converting from a semantic component, such as a <code>color</code> or <code>shape</code>, to a string. See <ahref="https://drafts.csswg.org/cssom/#serializing-css-values">here</a> for a comprehensive list of CSS "serializations" and <ahref="https://drafts.csswg.org/cssom/#serializing-css-values-examples">here</a> for some specific serialization examples. Perhaps my understanding of serialization is flawed.
0 commit comments