Preserve unresolved linked CSS selectors

AI assistance disclosure: Codex implemented and verified this fix under maintainer direction.
This commit is contained in:
Paul Bakaus
2026-09-02 09:30:26 -07:00
parent 45148003af
commit 0fa4202ca9
4 changed files with 30 additions and 2 deletions
+6 -1
View File
@@ -1332,7 +1332,12 @@ if (IS_BROWSER) {
}
const cssText = rule.cssText || '';
if (rule.selectorText) {
if (selectorNodesForLiveDom(document, rule.selectorText)?.length > 0) parts.push(cssText);
const matches = selectorNodesForLiveDom(document, rule.selectorText);
// A null result means the DOM selector API cannot resolve the CSSOM
// selector (commonly a hostless pseudo-element), not that it is
// unused. Keep those valid stylesheet rules; only a definitive empty
// result proves that no live element can receive the declaration.
if (matches === null || matches.length > 0) parts.push(cssText);
continue;
}
let nested = [];
+6 -1
View File
@@ -8233,7 +8233,12 @@ if (IS_BROWSER) {
}
const cssText = rule.cssText || '';
if (rule.selectorText) {
if (selectorNodesForLiveDom(document, rule.selectorText)?.length > 0) parts.push(cssText);
const matches = selectorNodesForLiveDom(document, rule.selectorText);
// A null result means the DOM selector API cannot resolve the CSSOM
// selector (commonly a hostless pseudo-element), not that it is
// unused. Keep those valid stylesheet rules; only a definitive empty
// result proves that no live element can receive the declaration.
if (matches === null || matches.length > 0) parts.push(cssText);
continue;
}
let nested = [];
@@ -1409,6 +1409,11 @@ describe('detectUrl — browser-only fixtures', () => {
assert.equal(stripes.length, 1, JSON.stringify({ linkedFindings, linkedCssom }));
assert.equal(stripes[0].severity, 'advisory');
assert.equal(stripes[0].advisory, true);
assert.equal(
linkedFindings.some(finding => finding.type === 'bounce-easing'),
true,
JSON.stringify({ linkedFindings, linkedCssom }),
);
assert.equal(linkedFindings.some(finding => finding.type === 'codex-grid-background'), false);
assert.equal(linkedFindings.some(finding => finding.type === 'layout-transition'), false);
await linkedPage.close();
+13
View File
@@ -6,6 +6,19 @@
}
}
/* A valid hostless pseudo-element selector cannot be queried through the DOM
selector API. It must remain in the corpus rather than count as unused. */
main > ::before {
content: "Rendered pseudo-element text";
display: block;
width: 160px;
animation: bounce-linked-pseudo 1s ease-in-out infinite;
}
@keyframes bounce-linked-pseudo {
50% { transform: translateY(2px); }
}
/* Shipped but unused selectors must remain outside live URL findings, even
inside grouping rules or when their check does not serialize a selector. */
@supports (display: grid) {