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
+18-14Lines changed: 18 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,9 @@ published: false
14
14
15
15
### Introduction
16
16
17
-
When browsing the [CSS Backgrounds 3 spec](https://www.w3.org/TR/2017/CR-css-backgrounds-3-20171017) a few days ago trying to determine the browser-default `background-color` of the viewport for use in [Kosmonaut](https://github.com/twilco/kosmonaut) (hint: it's system and browser dependent), I stumbled across this note in the changelog:
17
+
A few days ago, I was browsing the [CSS Backgrounds 3 spec](https://www.w3.org/TR/2017/CR-css-backgrounds-3-20171017) trying to determine the browser-default `background-color` of the viewport for use in [Kosmonaut](https://github.com/twilco/kosmonaut) (hint: it's system and browser dependent).
18
+
19
+
In doing so, I stumbled across this note in the changelog:
18
20
19
21
{:refdef: style="text-align: center;"}
20
22
<ahref="/assets/img/background_serialization/bg_serialization_change.png"></a>
@@ -23,13 +25,13 @@ When browsing the [CSS Backgrounds 3 spec](https://www.w3.org/TR/2017/CR-css-bac
23
25
Clicking into the <code><final-bg-layer></code> hyperlink, we discover this revision changed the serialization order of the `background` shorthand property:
24
26
25
27
{:refdef: style="text-align: center;"}
26
-
<ahref="/assets/img/background_serialization/bg_serialization_change.png"></a>
28
+
<ahref="/assets/img/background_serialization/background_shorthand_definition.png"></a>
27
29
{:refdef}
28
30
<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>
29
31
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?
32
+
This intrigued me. Why do authors expect the color to be first, and why does it make less sense for the color to be first? What does this change mean in practicality? How was this decision to change the specification made?
31
33
32
-
Read on for a glimpse into [how the CSS sausage is made](https://en.wiktionary.org/wiki/how_the_sausage_gets_made), from CSS specification to (often differing) browser implementation.
34
+
Read on for a glimpse into [how the CSS sausage is made](https://en.wiktionary.org/wiki/how_the_sausage_gets_made), from CSS specification to (sometimes differing) browser implementation. You can expect to learn about the CSS standards process, CSS serialization, web platform tests, and more, hopefully gaining some appreciation for the difficult task that web compatibility is.
33
35
34
36
### First, a detour: how CSS comes to be
35
37
@@ -132,25 +134,25 @@ The order in which properties are serialized could be very important. For examp
132
134
133
135
### So why was this change made?
134
136
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):
137
+
Development of these specifications [happens on Github](https://github.com/w3c/csswg-drafts), so let's look at [the commit that introduced this change](https://github.com/w3c/csswg-drafts/commit/02fe11230e02279b495e4c5931be6ed5bab61c5c):
136
138
137
139
{:refdef: style="text-align: center;"}
138
140
<ahref="/assets/img/background_serialization/background_serialization_commit.png"></a>
139
141
{:refdef}
140
142
141
-
Clicking on the [pictured hyperlink](https://lists.w3.org/Archives/Public/www-style/2015Jan/0406.html) takes us to the meeting notes — search for "background serialization" to find the bit we're interested in.
143
+
Clicking on the [pictured hyperlink](https://lists.w3.org/Archives/Public/www-style/2015Jan/0406.html) takes us to a set of CSSWG telecon meeting notes from 2015. Search for "background serialization" to find the bit we're interested in.
142
144
143
145
Feel free to read the full conversation yourself — for the sake of brevity, here is a summary of points:
144
146
145
147
<olclass="bold slightly-spaced-list">
146
148
<li>
147
149
<span class="non-bold">
148
-
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.
150
+
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 <code><final-background-layer></code> value list.
149
151
</span>
150
152
</li>
151
153
<li>
152
154
<span class="non-bold">
153
-
For CSS3, the <code><background-color></code> was moved to the end of the finalbackgroundlayer because it is painted underneath all the other components of this layer (e.g. the background image and all its modifiers).
155
+
For CSS3, the <code><background-color></code> was moved to the end of the <code><final-background-layer></code> because it is painted underneath all the other components of this layer (e.g. the background image and all its modifiers).
154
156
</span>
155
157
</li>
156
158
<li>
@@ -177,27 +179,29 @@ This 2015 spec revision was not the end of the confusion surrounding `background
177
179
<ahref="/assets/img/background_serialization/serialization_questions.png"></a>
178
180
{:refdef}
179
181
180
-
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.
181
-
182
-
TODO: Wait, they're all wrong in lots of different ways! Write about this.
182
+
And roughly two years after this issue was opened, [it was noted in a comment](https://github.com/w3c/csswg-drafts/issues/418#issuecomment-380951618) that this inconsistency across browsers still existed. In fact, the linked comment shows all browsers serialized `background` wrong relative to the spec, each in different ways.
183
183
184
184
### Web platform tests: the ultimate equalizer
185
185
186
-
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):
186
+
There is a somewhat 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):
187
187
188
188
> 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.
189
189
190
190
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!
191
191
192
192
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.
As you might now be guessing, [a WPT was created](https://github.com/web-platform-tests/wpt/pull/10462/files) to more rigidly enforce all the various ways the `background` shorthand property may be serialized. This is still not ideal, as the test considers five different serializations (spec, Edge, Firefox, Blink, and WebKit) valid, but it's a great step forward. With this test in place, it's at least made clear to authors what serializations they could and should expect if they decide to rely on this API.
195
195
196
-
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.
196
+
Making use of the aforementioned dashboard, we can view the [results of this WPT](https://wpt.fyi/results/css/css-backgrounds/parsing/background-valid.html?label=master&label=experimental&aligned&q=background-valid)for each browser — as is expected, all pass!
197
197
198
198
### Summary
199
199
200
200
In summary, web compatibility is hard. Thank your local browser developer when you next get a chance :)
201
201
202
202
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).
203
203
204
+
---
205
+
<divclass="paragraph-sized-spacer"></div>
206
+
207
+
For some extra credit reading, [check out this discussion](https://github.com/w3c/csswg-drafts/issues/1033) concerning the serialization of computed CSS styles returned from [Window.getComputedStyle()](https://developer.mozilla.org/en-US/docs/Web/API/Window/getComputedStyle). There's some interesting back-and-forth on the validity of serializing the object to an empty string vs. something "meaningful", and the technical difficulties that would come with that.
0 commit comments