mirror of
https://github.com/jlengrand/webcomponentsjs.git
synced 2026-05-17 15:56:21 +00:00
Only upgrade imports once
This commit is contained in:
@@ -311,9 +311,11 @@ var CustomElementDefinition;
|
||||
|
||||
/**
|
||||
* @param {NodeList} nodeList
|
||||
* @param {Set<Node>=} visitedNodes
|
||||
* @private
|
||||
*/
|
||||
_addNodes: function(nodeList) {
|
||||
_addNodes: function(nodeList, visitedNodes) {
|
||||
visitedNodes = visitedNodes || new Set();
|
||||
for (var i = 0; i < nodeList.length; i++) {
|
||||
var root = nodeList[i];
|
||||
|
||||
@@ -342,15 +344,18 @@ var CustomElementDefinition;
|
||||
if (node.shadowRoot) {
|
||||
// TODO(justinfagnani): do we need to check that the shadowRoot
|
||||
// is observed?
|
||||
this._addNodes(node.shadowRoot.childNodes);
|
||||
this._addNodes(node.shadowRoot.childNodes, visitedNodes);
|
||||
}
|
||||
if (node.tagName === 'LINK' && node.rel.toLowerCase() === 'import') {
|
||||
if (node.tagName === 'LINK' &&
|
||||
node.rel.toLowerCase() === 'import' &&
|
||||
!visitedNodes.has(node)) {
|
||||
// visitedNodes.add(node);
|
||||
var onLoad = (function() {
|
||||
var link = node;
|
||||
return function() {
|
||||
link.removeEventListener('load', onLoad);
|
||||
this._observeRoot(link.import);
|
||||
this._addNodes(link.import.childNodes);
|
||||
this._addNodes(link.import.childNodes, visitedNodes);
|
||||
}.bind(this);
|
||||
}).bind(this)();
|
||||
if (node.import) {
|
||||
|
||||
@@ -1 +1,2 @@
|
||||
<link rel="import" href="sub-import.html">
|
||||
<x-foo></x-foo>
|
||||
|
||||
@@ -33,14 +33,18 @@
|
||||
<script src="../../../../dist/HTMLImports.js"></script>
|
||||
<script src="../../../../src/CustomElements/v1/CustomElements.js"></script>
|
||||
<script src="../../../../../web-component-tester/browser.js"></script>
|
||||
<link rel="import" href="sub-import.html" id="sub-import">
|
||||
<link rel="import" href="imported-doc.html" id="import">
|
||||
<link rel="not-import" href="imported-doc.html" id="import">
|
||||
<link rel="not-import" href="imported-doc.html" id="not-import">
|
||||
<script>
|
||||
customElements.enableFlush = true;
|
||||
var elementsCreated = 0;
|
||||
var nonImportDocumentAccessed = false;
|
||||
var subImportDocumentAccessCount = 0;
|
||||
|
||||
var nonImportLink = document.querySelector('link[rel="not-import"]');
|
||||
// To tell if CustomElementsRegistry tries to import a non-import link
|
||||
// we fail if the .import accessor is read.
|
||||
var nonImportLink = document.querySelector('#not-import');
|
||||
Object.defineProperty(nonImportLink, 'import', {
|
||||
get: function() {
|
||||
nonImportDocumentAccessed = true;
|
||||
@@ -48,6 +52,15 @@
|
||||
enumberable: true,
|
||||
});
|
||||
|
||||
var subImportLink = document.querySelector('#sub-import');
|
||||
Object.defineProperty(subImportLink, 'import', {
|
||||
get: function() {
|
||||
subImportDocumentAccessCount++;
|
||||
},
|
||||
enumberable: true,
|
||||
});
|
||||
|
||||
|
||||
class XFoo extends HTMLElement {
|
||||
constructor() {
|
||||
console.log("XFoo");
|
||||
@@ -67,6 +80,10 @@
|
||||
chai.assert.isFalse(nonImportDocumentAccessed, 'CustomElements is trying to upgrade a non-import link');
|
||||
});
|
||||
|
||||
test('CustomElements only upgrades a <link rel=import> once', function() {
|
||||
chai.assert.equal(subImportDocumentAccessCount, 1);
|
||||
});
|
||||
|
||||
});
|
||||
</script>
|
||||
</head>
|
||||
|
||||
1
tests/CustomElements/v1/html/sub-import.html
Normal file
1
tests/CustomElements/v1/html/sub-import.html
Normal file
@@ -0,0 +1 @@
|
||||
<div></div>
|
||||
Reference in New Issue
Block a user