Skip to content

🐛 fix(css): bound child-led :has() walks - #2271

Merged
gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/has-multi-compound-1821
Nov 16, 2026
Merged

gaborbernat merged 1 commit into
tox-dev:mainfrom
gaborbernat:fix/has-multi-compound-1821

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Matching a :has() argument with several compounds and a child or sibling lead took time that grew with the square of the nesting depth on deep trees. Each candidate anchor walked its whole subtree, although such an argument can reach only as many levels below the anchor as it has compounds. Matching now stops at that depth, so the cost follows the elements those levels reach. Fixes #2262.

The walk ignored the argument's depth

The old walk was sel_has_subtree. It visited every descendant of the anchor for each candidate, even though a child or sibling chain cannot place its subject deeper than the number of its compounds. Descendant arguments already reuse answers on deep trees, so only this form was left unbounded.

Such an argument now takes sel_has_levels, which recurses into a child only while a level of the argument remains. The unbounded walk stays for arguments with a descendant combinator.

Behavior changes

Match results do not change. Only the time spent on child- or sibling-led multi-compound :has() arguments on deep trees changes.

Reported by Anthropic OSS Scanner: ANT-2026-IBDOALZF.

A :has() argument with several compounds and a child or sibling lead
walked the whole subtree of every anchor, although its subject sits at
most as many levels below the anchor as the argument has compounds.
On a deep tree the total work grew with the square of the depth. The
walk now stops at that level, so the cost follows the levels the
argument names.

Fixes tox-dev#2262
@gaborbernat gaborbernat added the bug Something isn't working label Nov 16, 2026
@gaborbernat
gaborbernat merged commit 294a289 into tox-dev:main Nov 16, 2026
1 of 48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Child-led :has() arguments cost grows with the square of depth

1 participant