@@ -9,13 +9,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
9
9
*/
10
10
11
11
import './boot.js' ;
12
- import { wrap } from './wrap.js' ;
13
12
14
13
const ShadyDOM = window . ShadyDOM ;
15
14
const ShadyCSS = window . ShadyCSS ;
16
15
17
16
/**
18
17
* Ensure that elements in a ShadowDOM container are scoped correctly.
18
+ * This function is only needed when ShadyDOM is used and unpatched DOM APIs are used in third party code.
19
+ * This can happen in noPatch mode or when specialized APIs like ranges or tables are used to mutate DOM.
19
20
*
20
21
* @param {!Element } container Container element to scope
21
22
* @param {boolean= } shouldObserve if true, start a mutation observer for added nodes to the container
@@ -26,8 +27,8 @@ export function scopeSubtree(container, shouldObserve = false) {
26
27
if ( ! ShadyDOM || ! ShadyCSS ) {
27
28
return null ;
28
29
}
29
- // ShadyCSS handles DOM mutations in patched mode
30
- if ( ! ShadyDOM [ 'noPatch ' ] ) {
30
+ // ShadyCSS handles DOM mutations when ShadyDOM does not handle scoping itself
31
+ if ( ! ShadyDOM [ 'handlesDynamicScoping ' ] ) {
31
32
return null ;
32
33
}
33
34
const ScopingShim = ShadyCSS [ 'ScopingShim' ] ;
@@ -39,8 +40,9 @@ export function scopeSubtree(container, shouldObserve = false) {
39
40
const containerScope = ScopingShim [ 'scopeForNode' ] ( container ) ;
40
41
41
42
const scopify = ( node ) => {
42
- const wrappedNode = wrap ( node ) ;
43
- const elements = [ node , ...( wrappedNode . querySelectorAll ( '*' ) ) ] ;
43
+ // NOTE: native qSA does not honor scoped DOM, but it is faster, and the same behavior as Polymer v1
44
+ const descendants = ShadyDOM [ 'nativeMethods' ] [ 'querySelectorAll' ] . call ( node , '*' ) ;
45
+ const elements = [ node , ...descendants ] ;
44
46
for ( let i = 0 ; i < elements . length ; i ++ ) {
45
47
const el = elements [ i ] ;
46
48
const currentScope = ScopingShim [ 'currentScopeForNode' ] ( el ) ;
0 commit comments