Skip to content

Commit 47f5499

Browse files
[CSS Modules] synchronously process blob URLs
After switching to Blob URL's in C:7075691, I noticed that the fetched stylesheet is not always available immediately in a fully declarative scenario (where both the style tag is a module and shadowrootadoptedstylesheets references it), which wasn't the case for dataURI's. Typically, the first n fetches fail to fetch, where n is random. I discovered that dataURI's were always synchronously returned from ResourceFetcher via CreateResourceForStaticData. To match this behavior with Blob URL's, this CL adds a new parameter to synchronously fetch Blob URL's when initiated via `shadowrootadoptedstylesheets`. Blob URL's remain async in all other scenarios. This behavior won't cause the same undesirable issues that synchronous XHR faced because Blob URL's are typically local (and will always be in-memory when generated via Declarative CSS Modules). A test was added that failed ~50% of the time without this change. This change will address the current undesirable behavior, but I'll investigate what this would look like to make fully async with a callback. This will take some time and will need input from the WHATWG so for now this change will make the current design usable. Bug: 448174611 Change-Id: If50701981f7eaa138fff7d9ca799431c3303fa72
1 parent 07448e7 commit 47f5499

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<!DOCTYPE html>
2+
<title>shadowrootadoptedstylesheets with Declarative CSS Module</title>
3+
<meta name="author" title="Kurt Catti-Schmidt" href="mailto:[email protected]" />
4+
<link rel='help' href='https://github.com/whatwg/html/pull/11687'>
5+
<script src='/resources/testharness.js'></script>
6+
<script src='/resources/testharnessreport.js'></script>
7+
8+
<style type="module" specifier="foo">
9+
span {color:blue}
10+
</style>
11+
12+
<div id="host">
13+
<template shadowrootmode="open" shadowrootadoptedstylesheets="foo">
14+
<span id="test_element">Test content</span>
15+
</template>
16+
</div>
17+
18+
<script>
19+
const host = document.getElementById("host");
20+
test(function (t) {
21+
assert_equals(
22+
host.shadowRoot.adoptedStyleSheets.length,
23+
1,
24+
"The shadowrootadoptedstylesheets will declaratively import named specifiers into the adoptedStyleSheets array.",
25+
);
26+
27+
}, "adoptedStyleSheets is populated from a <template> element's shadowrootadoptedstylesheets attribute.");
28+
const test_element = host.shadowRoot.getElementById("test_element");
29+
30+
test(function (t) {
31+
assert_equals(getComputedStyle(test_element)
32+
.color, "rgb(0, 0, 255)",
33+
"Declarative styles were applied.");
34+
35+
}, "Styles from the adoptedStyleSheets are applied to elements.");
36+
</script>

0 commit comments

Comments
 (0)