Skip to content

Commit

Permalink
core(tags-blocking-first-paint): ignore malformed link tags (#15489)
Browse files Browse the repository at this point in the history
  • Loading branch information
adamraine authored Sep 21, 2023
1 parent 7d46afa commit aa8d489
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cli/test/fixtures/dobetterweb/dbw_tester.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<!-- Alternate stylesheets should not show in TagsBlockingFirstPaint artifact -->
<link rel="alternate stylesheet" href="./empty.css">

<!-- Malformed links should not show in TagsBlockingFirstPaint artifact -->
<link rel="stylesheet" href="">

<!-- FAIL: block rendering -->
<script src="./dbw_tester.js" id="dbw-tester-script"></script>

Expand Down
9 changes: 9 additions & 0 deletions cli/test/smokehouse/test-definitions/dobetterweb.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ const expectations = {
crossOrigin: null,
source: 'head',
},
{
rel: 'stylesheet',
href: 'http://localhost:10200/dobetterweb/dbw_tester.html',
hrefRaw: '',
hreflang: '',
as: '',
crossOrigin: null,
source: 'head',
},
{
rel: 'stylesheet',
href: 'http://localhost:10200/dobetterweb/dbw_tester.css?scriptActivated&delay=200',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ async function collectTagsThatBlockFirstPaint() {
/** @type {Array<LinkTag>} */
const linkTags = [...document.querySelectorAll('link')]
.filter(linkTag => {
// Ignore malformed links with no href (e.g. `<link rel="stylesheet" href="">`)
// The resolved `linkTag.href` will be the main document, but the main document
// should never be render blocking.
if (!linkTag.getAttribute('href')) return false;

// Filter stylesheet/HTML imports that block rendering.
// https://www.igvita.com/2012/06/14/debunking-responsive-css-performance-myths/
// https://www.w3.org/TR/html-imports/#dfn-import-async-attribute
Expand Down

0 comments on commit aa8d489

Please sign in to comment.