jquery / sizzle

A sizzlin' hot selector engine.
https://sizzlejs.com
Other
6.29k stars 951 forks source link

Selector: Leverage the :scope pseudo-class where possible #453

Closed mgol closed 5 years ago

mgol commented 5 years ago

The :scope pseudo-class[1] has surprisingly good browser support: Chrome, Firefox & Safari have supported if for a long time; only IE & Edge lack support. This commit leverages this pseudo-class to get rid of the ID hack in most cases. Adding a temporary ID may cause layout thrashing which was reported a few times in [the past.

We can't completely eliminate the ID hack in modern browses as sibling selectors require us to change context to the parent and then :scope stops applying to what we'd like. But it'd still improve performance in the vast majority of cases.

[1] https://developer.mozilla.org/en-US/docs/Web/CSS/:scope

Fixes jquery/jquery#4453 Ref jquery/jquery#4454 Ref jquery/jquery#4332 Ref gh-405

mgol commented 5 years ago

+47 bytes as of 53b7f5d8adc37450fcfec0649bbb6aad58d0529d.