8000 [selectors-4] Consider disallowing :has() outside the rightmost compound · Issue #6845 · w3c/csswg-drafts · GitHub
[go: up one dir, main page]

Skip to content

[selectors-4] Consider disallowing :has() outside the rightmost compound #6845

@anttijk

Description

@anttijk

Consider a rule like

:has(.foo) div { ... }

With this, style of every div in the document becomes dependent on the class lists of every element in the document. Specific cases can be optimized but in general case this means the engine has to do expensive full-document invalidation (or style recalc) on every document mutation (or pseudo class change) that may affect :has results. This is a potential performance footgun.

The invalidation scope can be drastically reduced by limiting :has() to rightmost compound only. This means that only ancestors/sibling chains needs to be considered for invalidation on :has()-affecting mutation. This is analogous to how only descendants/siblings need to be considered for regular selectors.

Sensible use cases for :has() are likely in the rightmost compound anyway so it seems better to not have this footgun around.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0