`:has(div + .a)` does not update when a `div` is inserted or removed
Categories
(Core :: CSS Parsing and Computation, defect)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox162 | --- | fixed |
People
(Reporter: jwatt, Assigned: jwatt)
References
(Blocks 1 open bug)
Details
Attachments
(1 external file)
In something like:
<style>.x:has(div + .a) { color: red }</style>
<div class=x><span class=a>a</span></div>
<script>
const x = document.querySelector(".x");
getComputedStyle(x).color; // flush style first
x.prepend(document.createElement("div"));
</script>
the text should turn red, but stays black, even though x.matches(".x:has(div + .a)") returns true. Removing the div again also fails to update.
The same happens with :has(> div + .a), :has(div ~ .a), :has(div + .a + .b), and :has(:not(.x) + .a) when the sibling has class x.
These work: :has(.d + .a) with an inserted <div class=d>, and :has(.a + div) with the div appended after the span.
The problem is that RelativeSelectorDependencyCollector creates compound_state_attributes once per :has() argument and only resets compound_state between compounds. Compounds are visited right to left, so once one compound sets added_entry, every compound to its left skips add_non_unique_info. A compound with no class, id, attribute or pseudo-class of its own (other than :not(), :is() and :where()) then gets no type_to_selector or any_to_selector entry, and so inserting or removing an element that only it matches fails to trigger invalidation. SelectorDependencyCollector resets both pieces of state at each compound.
The selector in bug 2088020 is affected too (its :not(.a .b) compound), but its testcase fails for a different reason.
| Assignee | ||
Comment 1•19 days ago
|
||
RelativeSelectorDependencyCollector::visit_whole_selector only reset
compound_state at the start of each compound, but not
compound_state_attributes (which is created once per relative selector).
Compounds are visited right to left, so once any compound sets added_entry,
every compound to its left skips add_non_unique_info, and a compound with
nothing of its own to key on (such as a class, id or attribute) gets no
type_to_selector or any_to_selector entry. Inserting or removing an element
that was only matched by such a compound selector (e.g. the div in
:has(div + .a)) would then fail to trigger invalidation.
(SelectorDependencyCollector already resets both at each compound.)
Created web-platform-tests PR https://github.com/web-platform-tests/wpt/pull/64945 for changes under testing/web-platform/tests
Comment 4•19 days ago
|
||
| bugherder | ||
Upstream PR merged by moz-wptsync-bot
Updated•1 day ago
|
Description
•