Skip to content

Commit

Permalink
Selector: Make selectors with leading combinators use qSA again
Browse files Browse the repository at this point in the history
An optimization added in jquery/sizzle#431 skips the temporary IDs for selectors
not using child or descendant combinators. For sibling combinators, though, this
pushes a selector with a leading combinator to qSA directly which crashes and
falls back to a slower Sizzle route.

This commit makes selectors with leading combinators not skip the selector
rewriting. Note that after jquery#4454 & jquery/sizzle#453, all modern
browsers other than Edge leverage the :scope pseudo-class, avoiding temporary
id attributes.

Ref jquerygh-4509
Ref jquery/sizzle#431
  • Loading branch information
mgol committed Oct 3, 2022
1 parent 0026510 commit 89e606d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/selector.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,11 @@ function find( selector, context, results, seed ) {
// descendant combinators, which is not what we want.
// In such cases, we work around the behavior by prefixing every selector in the
// list with an ID selector referencing the scope context.
// The technique has to be used as well when a leading combinator is used
// as such selectors are not recognized by querySelectorAll.
// Thanks to Andrew Dupont for this technique.
if ( nodeType === 1 && rdescend.test( selector ) ) {
if ( nodeType === 1 &&
( rdescend.test( selector ) || rcombinators.test( selector ) ) ) {

// Expand context for sibling selectors
newContext = rsibling.test( selector ) && testContext( context.parentNode ) ||
Expand Down

0 comments on commit 89e606d

Please sign in to comment.