-
Notifications
You must be signed in to change notification settings - Fork 746
Description
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.