Skip to content

Commit 1f9e257

Browse files
author
Steven Orvell
committed
Fixes #72. (wip, needs more testing)
1 parent 7f11f5f commit 1f9e257

File tree

3 files changed

+79
-16
lines changed

3 files changed

+79
-16
lines changed

src/shady/element-mixin.html

+8-5
Original file line numberDiff line numberDiff line change
@@ -165,13 +165,16 @@
165165
(Tree.Logical.getParentNode(fragContent).nodeType !==
166166
Node.DOCUMENT_FRAGMENT_NODE);
167167
var hasContent = fragContent || (node.localName === insertionPointTag);
168-
// There are 3 possible cases where a distribution may need to occur:
169-
// 1. <content> being inserted (the host of the shady root where
168+
// There are 4 possible cases where a distribution may need to occur:
169+
// 1. ownerRoot has never distributed
170+
// 2. <content> being inserted (the host of the shady root where
170171
// content is inserted needs distribution)
171-
// 2. children being inserted into parent with a shady root (parent
172+
// 3. children being inserted into parent with a shady root (parent
172173
// needs distribution)
173-
// 3. container is an insertionPoint
174-
if (hasContent || (container.localName === insertionPointTag)) {
174+
// 4. container is an insertionPoint
175+
var needsInitialDistribution = ownerRoot && !ownerRoot._hasDistributed;
176+
if (needsInitialDistribution || hasContent ||
177+
(container.localName === insertionPointTag)) {
175178
if (ownerRoot) {
176179
// note, insertion point list update is handled after node
177180
// mutations are complete

test/smoke/shady-basic.html

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<!doctype html>
2+
<!--
3+
@license
4+
Copyright (c) 2014 The Polymer Project Authors. All rights reserved.
5+
This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt
6+
The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt
7+
The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt
8+
Code distributed by Google as part of the polymer project is also
9+
subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt
10+
-->
11+
<html>
12+
<head>
13+
<title>Polymer - shady</title>
14+
<meta charset="utf-8">
15+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
16+
<script src="../../../webcomponentsjs/webcomponents-lite.js"></script>
17+
<link rel="import" href="../../polymer.html">
18+
</head>
19+
<body>
20+
21+
<dom-module id="base-el">
22+
<template>
23+
<div>in shadow</div>
24+
</template>
25+
26+
<script>
27+
class BaseEl extends Polymer.Element {
28+
static get is() { return 'base-el' }
29+
}
30+
customElements.define(BaseEl.is, BaseEl);
31+
</script>
32+
</dom-module>
33+
34+
<base-el>
35+
<div>hi</div>
36+
</base-el>
37+
38+
</body>
39+
</html>

test/unit/shady-v1.html

+32-11
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<html>
1212
<head>
1313
<meta charset="utf-8">
14-
<script src="../../../webcomponentsjs/webcomponents-lite.js"
14+
<script src="../../../webcomponentsjs/webcomponents-lite.js"
1515
ce="v1" register="true"></script>
1616
<script src="../../../web-component-tester/browser.js"></script>
1717
<script>
@@ -44,12 +44,33 @@
4444
registerTestElement();
4545
// Create an instance of the test element.
4646
var host = document.createElement('x-content-test');
47+
// Populate the initial pool of light DOM children.
48+
host.innerHTML = hostInnerHtml;
4749
document.body.appendChild(host);
4850
CustomElements.takeRecords();
51+
// Pretend we're stamping the template contents.
52+
host.shadyRoot.innerHTML = shadowRootHtml;
53+
// Invoke distribution and verify the resulting tree.
54+
ShadyDom.flush();
55+
assert.strictEqual(getComposedHTML(host), expectedHtml);
56+
document.body.removeChild(host);
57+
});
58+
test(descr + ' fragment', function() {
59+
registerTestElement();
60+
// Create an instance of the test element.
61+
var host = document.createElement('x-content-test');
4962
// Populate the initial pool of light DOM children.
5063
host.innerHTML = hostInnerHtml;
64+
document.body.appendChild(host);
65+
CustomElements.takeRecords();
5166
// Pretend we're stamping the template contents.
52-
host.shadyRoot.innerHTML = shadowRootHtml
67+
var div = document.createElement('div');
68+
div.innerHTML = shadowRootHtml;
69+
var frag = document.createDocumentFragment();
70+
while (div.firstChild) {
71+
frag.appendChild(div.firstChild);
72+
}
73+
host.shadyRoot.appendChild(frag);
5374
// Invoke distribution and verify the resulting tree.
5475
ShadyDom.flush();
5576
assert.strictEqual(getComposedHTML(host), expectedHtml);
@@ -75,7 +96,7 @@
7596
testRender('select ""', '<a href="">Link</a> <b>bold</b>',
7697
'<slot></slot>',
7798
'<a href="">Link</a> <b>bold</b>');
78-
99+
79100
testRender('slot a',
80101
'<a slot="a">a</a> <a slot="b">b</a>',
81102
'<slot name="a"></slot>',
@@ -106,7 +127,7 @@
106127
host.innerHTML = '<a></a>';
107128
// pre-distirbution grab first composed node.
108129
var a = getComposedChildAtIndex(host, 0);
109-
130+
110131
host.shadyRoot.innerHTML = '<x-content-test id="p"></x-content-test>';
111132
// force upgrade on polyfilled browsers
112133
var p = host.shadyRoot.firstChild;
@@ -159,7 +180,7 @@
159180

160181
test('removeAllChildNodes - mutate host', function() {
161182
host.innerHTML = '<a>Hello</a>';
162-
183+
163184
host.shadyRoot.innerHTML = '<slot>fallback</slot>';
164185
ShadyDom.flush();
165186
assert.strictEqual(getComposedHTML(host), '<a>Hello</a>');
@@ -176,7 +197,7 @@
176197

177198
test('removeAllChildNodes - mutate shadow', function() {
178199
host.innerHTML = '<a>Hello</a>';
179-
200+
180201
host.shadyRoot.innerHTML = '<slot></slot><b>after</b>';
181202
ShadyDom.flush();
182203
assert.strictEqual(getComposedHTML(host), '<a>Hello</a><b>after</b>');
@@ -192,7 +213,7 @@
192213

193214
test('removeAllChildNodes - mutate shadow fallback', function() {
194215
host.innerHTML = '<a>Hello</a>';
195-
216+
196217
host.shadyRoot.innerHTML = '<slot name="xxx"><b>fallback</b></slot>';
197218
var b = host.shadyRoot.firstChild.firstChild;
198219
ShadyDom.flush();
@@ -213,7 +234,7 @@
213234

214235
test('removeChild - mutate host', function() {
215236
host.innerHTML = '<a>Hello</a>';
216-
237+
217238
host.shadyRoot.innerHTML = '<slot>fallback</slot>';
218239
ShadyDom.flush();
219240
assert.strictEqual(getComposedHTML(host), '<a>Hello</a>');
@@ -247,7 +268,7 @@
247268

248269
test('removeChild - mutate shadow', function() {
249270
host.innerHTML = '<a>Hello</a>';
250-
271+
251272
host.shadyRoot.innerHTML = '<slot></slot><b>after</b>';
252273
var b = host.shadyRoot.lastChild;
253274
ShadyDom.flush();
@@ -269,7 +290,7 @@
269290
test('setAttribute slot', function() {
270291
host.innerHTML = '<a slot="a">Hello</a><b slot="b">World</b>';
271292

272-
293+
273294
host.shadyRoot.innerHTML = '<slot name="b">fallback b</slot>' +
274295
'<slot name="a">fallback a</slot>';
275296
ShadyDom.flush();
@@ -325,7 +346,7 @@
325346
test('insertBefore - mutate shadow', function() {
326347
host.innerHTML = '<a>Hello</a>';
327348

328-
349+
329350
host.shadyRoot.innerHTML = '<slot></slot>';
330351
var content = host.shadyRoot.firstChild;
331352
ShadyDom.flush();

0 commit comments

Comments
 (0)