Skip to content
Browse files

Fixes #2235. Manages logical information in shady distribution more d…

…irectly by capturing it explicitly when needed and not whenever distribution is run.
  • Loading branch information...
1 parent c4a9413 commit 21500fb53f4dc186ffd1099d5492c711e097c8a4 @sorvell sorvell committed
View
8 src/lib/dom-api.html
@@ -223,8 +223,14 @@
},
_updateInsertionPoints: function(host) {
- host.shadyRoot._insertionPoints =
+ var i$ = host.shadyRoot._insertionPoints =
factory(host.shadyRoot).querySelectorAll(CONTENT);
+ // ensure <content>'s and their parents have logical dom info.
+ for (var i=0, c; i < i$.length; i++) {
+ c = i$[i];
+ saveLightChildrenIfNeeded(c);
+ saveLightChildrenIfNeeded(factory(c).parentNode);
+ }
},
// a node is in a shadyRoot, is a shadyRoot,
View
18 src/mini/shady.html
@@ -53,11 +53,19 @@
this.shadyRoot._isShadyRoot = true;
this.shadyRoot._dirtyRoots = [];
// capture insertion point list
- this.shadyRoot._insertionPoints = !this._notes ||
+ var i$ = this.shadyRoot._insertionPoints = !this._notes ||
this._notes._hasContent ?
this.shadyRoot.querySelectorAll('content') : [];
- // save logical tree info for shadyRoot.
+ // save logical tree info
+ // a. for shadyRoot
+ // b. for insertion points (fallback)
+ // c. for parents of insertion points
saveLightChildrenIfNeeded(this.shadyRoot);
+ for (var i=0, c; i < i$.length; i++) {
+ c = i$[i];
+ saveLightChildrenIfNeeded(c);
+ saveLightChildrenIfNeeded(c.parentNode);
+ }
this.shadyRoot.host = this;
},
@@ -406,9 +414,6 @@
}
// remove child from its old parent first
remove(newChild);
- // make sure we never lose logical DOM information:
- // if the parentNode doesn't have lightChildren, save that information now.
- saveLightChildrenIfNeeded(parentNode);
// insert it into the real DOM
nativeInsertBefore.call(parentNode, newChild, refChild || null);
newChild._composedParent = parentNode;
@@ -417,9 +422,6 @@
function remove(node) {
var parentNode = getComposedParent(node);
if (parentNode) {
- // make sure we never lose logical DOM information:
- // if the parentNode doesn't have lightChildren, save that information now.
- saveLightChildrenIfNeeded(parentNode);
node._composedParent = null;
// remove it from the real DOM
nativeRemoveChild.call(parentNode, node);
View
6 test/unit/polymer-dom-shadow.html
@@ -47,6 +47,12 @@
<x-redistribute-a-b></x-redistribute-a-b>
+<div id="container">
+ <x-echo></x-echo>
+ <span>1</span>
+ <span>2</span>
+</div>
+
<script src="polymer-dom.js"></script>
</body>
View
6 test/unit/polymer-dom.html
@@ -47,6 +47,12 @@
<x-redistribute-a-b></x-redistribute-a-b>
+<div id="container">
+ <x-echo></x-echo>
+ <span>1</span>
+ <span>2</span>
+</div>
+
<script src="polymer-dom.js"></script>
</body>
View
28 test/unit/polymer-dom.js
@@ -424,6 +424,34 @@ suite('Polymer.dom', function() {
assert.equal(Polymer.dom(rere.root).querySelectorAll('span').length, 0);
});
+ test('appendChild interacts with unmanaged parent tree', function() {
+ var container = document.querySelector('#container');
+ var echo = Polymer.dom(container).firstElementChild;
+ assert.equal(echo.localName, 'x-echo');
+ var s1 = Polymer.dom(echo).nextElementSibling;
+ assert.equal(s1.textContent, '1');
+ var s2 = Polymer.dom(s1).nextElementSibling;
+ assert.equal(s2.textContent, '2');
+ assert.equal(Polymer.dom(container).children.length, 3);
+ Polymer.dom(echo).appendChild(s1);
+ Polymer.dom.flush();
+ assert.equal(Polymer.dom(container).children.length, 2);
+ assert.equal(Polymer.dom(echo).nextElementSibling, s2);
+ Polymer.dom(echo).appendChild(s2);
+ Polymer.dom.flush();
+ assert.equal(Polymer.dom(container).children.length, 1);
+ assert.equal(Polymer.dom(echo).nextElementSibling, null);
+ Polymer.dom(container).appendChild(s1);
+ Polymer.dom.flush();
+ assert.equal(Polymer.dom(container).children.length, 2);
+ assert.equal(Polymer.dom(echo).nextElementSibling, s1);
+ Polymer.dom(container).appendChild(s2);
+ Polymer.dom.flush();
+ assert.equal(Polymer.dom(container).children.length, 3);
+ assert.equal(Polymer.dom(echo).nextElementSibling, s1);
+ assert.equal(Polymer.dom(s1).nextElementSibling, s2);
+ });
+
test('distribute (forced)', function() {
var rere = Polymer.dom(testElement.root).querySelector('x-rereproject');
var re = Polymer.dom(rere.root).querySelector('x-reproject');
View
2 test/unit/shady.html
@@ -473,7 +473,7 @@
}
function updateRootInsertionPoints(root) {
- root._insertionPoints = root.querySelectorAll('content');
+ Polymer.dom(root.host)._updateInsertionPoints(root.host);
}
function getComposedHTML(node) {

0 comments on commit 21500fb

Please sign in to comment.
Something went wrong with that request. Please try again.