Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[renderblocking] Don't cancel implicit render-blocking when blocking attribute is removed #33798

Merged
merged 1 commit into from
May 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<!DOCTYPE html>
<title>Synchronous script element still blocks rendering after removing `blocking=render`</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/test-render-blocking.js"></script>

<script>
// Test script must be added before the synchronous script because the
// synchronous script is parser-blocking.

promise_setup(async () => {
let script = await nodeInserted(document.head, node => node.id === 'script');
script.blocking = '';

// Also inserts some contents for non-compliant UA to render
document.body = document.createElement('body');
document.body.appendChild(document.createTextNode('Some text'));
});

test_render_blocking(
() => assert_equals(window.dummy, 1),
'Render-blocking script is loaded and evaluated');
</script>

<script id="script" blocking="render" src="support/dummy-1.js?pipe=trickle(d1)"></script>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<!DOCTYPE html>
<title>Parser-inserted style element still blocks rendering after removing `blocking=render`</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/test-render-blocking.js"></script>

<script>
// Test script must be added before the style element because the style
// element is script-blocking.

promise_setup(async () => {
let sheet = await nodeInserted(document.head, node => node.id === 'sheet');
sheet.blocking = '';
});

test_render_blocking(
() => {
let color = getComputedStyle(document.querySelector('.target')).color;
assert_equals(color, 'rgb(255, 0, 0)');
},
'Render-blocking stylesheet is applied');
</script>

<style id="sheet" blocking="render">
@import url("support/target-red.css?pipe=trickle(d1)");
</style>

<div class="target">Some text</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<title>Parser-inserted stylesheet link still blocks rendering after removing `blocking=render`</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support/test-render-blocking.js"></script>

<script>
// Test script must be added before the stylesheet link because the stylesheet
// link is script-blocking.

promise_setup(async () => {
let sheet = await nodeInserted(document.head, node => node.id === 'sheet');
sheet.blocking = '';
});

test_render_blocking(
() => {
let color = getComputedStyle(document.querySelector('.target')).color;
assert_equals(color, 'rgb(255, 0, 0)');
},
'Render-blocking stylesheet is applied');
</script>

<link id="sheet" rel="stylesheet" blocking="render"
href="support/target-red.css?pipe=trickle(d1)">

<div class="target">Some text</div>
16 changes: 16 additions & 0 deletions html/dom/render-blocking/support/test-render-blocking.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ class LoadObserver {
}
}

// Observes the insertion of a script/parser-blocking element into DOM via
// MutationObserver, so that we can access the element before it's loaded.
function nodeInserted(parentNode, predicate) {
return new Promise(resolve => {
function callback(mutationList) {
for (let mutation of mutationList) {
for (let node of mutation.addedNodes) {
if (predicate(node))
resolve(node);
}
}
}
new MutationObserver(callback).observe(parentNode, {childList: true});
});
}

function createAutofocusTarget() {
const autofocusTarget = document.createElement('textarea');
autofocusTarget.setAttribute('autofocus', '');
Expand Down