Skip to content

Commit d287791

Browse files
committed
Selector: Make selectors with leading combinators use qSA again
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
1 parent aaaf870 commit d287791

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/selector.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -242,8 +242,11 @@ function find( selector, context, results, seed ) {
242242
// descendant combinators, which is not what we want.
243243
// In such cases, we work around the behavior by prefixing every selector in the
244244
// list with an ID selector referencing the scope context.
245+
// The technique has to be used as well when a leading combinator is used
246+
// as such selectors are not recognized by querySelectorAll.
245247
// Thanks to Andrew Dupont for this technique.
246-
if ( nodeType === 1 && rdescend.test( selector ) ) {
248+
if ( nodeType === 1 &&
249+
( rdescend.test( selector ) || rcombinators.test( selector ) ) ) {
247250

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

0 commit comments

Comments
 (0)