Skip to content

Commit e10019a

Browse files
committed
Use native qSA
Add documentation about when to use scopeSubtree
1 parent 6bc9534 commit e10019a

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

lib/utils/scope-subtree.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,14 @@ subject to an additional IP rights grant found at http://polymer.github.io/PATEN
99
*/
1010

1111
import './boot.js';
12-
import { wrap } from './wrap.js';
1312

1413
const ShadyDOM = window.ShadyDOM;
1514
const ShadyCSS = window.ShadyCSS;
1615

1716
/**
1817
* 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.
1920
*
2021
* @param {!Element} container Container element to scope
2122
* @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) {
2627
if (!ShadyDOM || !ShadyCSS) {
2728
return null;
2829
}
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']) {
3132
return null;
3233
}
3334
const ScopingShim = ShadyCSS['ScopingShim'];
@@ -39,8 +40,9 @@ export function scopeSubtree(container, shouldObserve = false) {
3940
const containerScope = ScopingShim['scopeForNode'](container);
4041

4142
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];
4446
for (let i = 0; i < elements.length; i++) {
4547
const el = elements[i];
4648
const currentScope = ScopingShim['currentScopeForNode'](el);

0 commit comments

Comments
 (0)