-
Notifications
You must be signed in to change notification settings - Fork 64
Adds attachShadow({shadyUpgradeFragment: documentFragment})
#316
Changes from 13 commits
6261855
71f9768
96be5a4
3091902
3da0f04
eb98d72
a0ce84a
f542a57
a67d835
d359957
4342887
003a148
2b355c2
59cff79
87c8e35
f70e34e
ba1a238
4eb1c12
3fb6f83
9fa8f8a
5d9f909
9dd608d
eb6e08a
d585fd4
5a77147
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,11 +12,10 @@ import * as utils from './utils.js'; | |
import {shadyDataForNode, ensureShadyDataForNode} from './shady-data.js'; | ||
import {patchInsideElementAccessors, patchOutsideElementAccessors} from './patch-instances.js'; | ||
|
||
function linkNode(node, container, ref_node) { | ||
function linkNode(node, container, containerData, ref_node) { | ||
patchOutsideElementAccessors(node); | ||
ref_node = ref_node || null; | ||
const nodeData = ensureShadyDataForNode(node); | ||
const containerData = ensureShadyDataForNode(container); | ||
const ref_nodeData = ref_node ? ensureShadyDataForNode(ref_node) : null; | ||
// update ref_node.previousSibling <-> node | ||
nodeData.previousSibling = ref_node ? ref_nodeData.previousSibling : | ||
|
@@ -54,17 +53,12 @@ export const recordInsertBefore = (node, container, ref_node) => { | |
} | ||
// handle document fragments | ||
if (node.nodeType === Node.DOCUMENT_FRAGMENT_NODE) { | ||
let c$ = node[utils.SHADY_PREFIX + 'childNodes']; | ||
for (let i=0; i < c$.length; i++) { | ||
linkNode(c$[i], container, ref_node); | ||
const first = node[utils.NATIVE_PREFIX + 'firstChild'] || null; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup, removing. |
||
for (let n = first; n; (n = n[utils.NATIVE_PREFIX + 'nextSibling'])) { | ||
linkNode(n, container, containerData, ref_node); | ||
} | ||
// cleanup logical dom in doc fragment. | ||
const nodeData = ensureShadyDataForNode(node); | ||
let resetTo = (nodeData.firstChild !== undefined) ? null : undefined; | ||
nodeData.firstChild = nodeData.lastChild = resetTo; | ||
nodeData.childNodes = resetTo; | ||
kevinpschaaf marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} else { | ||
linkNode(node, container, ref_node); | ||
linkNode(node, container, containerData, ref_node); | ||
} | ||
} | ||
|
||
|
@@ -97,23 +91,26 @@ export const recordRemoveChild = (node, container) => { | |
} | ||
|
||
/** | ||
* @param {!Node} node | ||
* @param {!Node|DocumentFragment} node | ||
* @param {!Node|DocumentFragment=} root | ||
*/ | ||
export const recordChildNodes = (node) => { | ||
export const recordChildNodes = (node, root) => { | ||
const nodeData = ensureShadyDataForNode(node); | ||
if (nodeData.firstChild === undefined) { | ||
// remove caching of childNodes | ||
nodeData.childNodes = null; | ||
const first = nodeData.firstChild = node[utils.NATIVE_PREFIX + 'firstChild'] || null; | ||
nodeData.lastChild = node[utils.NATIVE_PREFIX + 'lastChild'] || null; | ||
patchInsideElementAccessors(node); | ||
for (let n = first, previous; n; (n = n[utils.NATIVE_PREFIX + 'nextSibling'])) { | ||
const sd = ensureShadyDataForNode(n); | ||
sd.parentNode = node; | ||
sd.nextSibling = n[utils.NATIVE_PREFIX + 'nextSibling'] || null; | ||
sd.previousSibling = previous || null; | ||
previous = n; | ||
patchOutsideElementAccessors(n); | ||
} | ||
if (!root && nodeData.firstChild !== undefined) { | ||
return; | ||
} | ||
root = root || node; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confusing to call this It might be good to call the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Changed to |
||
// remove caching of childNodes | ||
nodeData.childNodes = null; | ||
const first = nodeData.firstChild = node[utils.NATIVE_PREFIX + 'firstChild'] || null; | ||
nodeData.lastChild = node[utils.NATIVE_PREFIX + 'lastChild'] || null; | ||
patchInsideElementAccessors(node); | ||
for (let n = first, previous; n; (n = n[utils.NATIVE_PREFIX + 'nextSibling'])) { | ||
const sd = ensureShadyDataForNode(n); | ||
sd.parentNode = root; | ||
sd.nextSibling = n[utils.NATIVE_PREFIX + 'nextSibling'] || null; | ||
sd.previousSibling = previous || null; | ||
previous = n; | ||
patchOutsideElementAccessors(n); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -36,8 +36,7 @@ export function clearNode(node) { | |
function removeOwnerShadyRoot(node) { | ||
// optimization: only reset the tree if node is actually in a root | ||
if (hasCachedOwnerRoot(node)) { | ||
let c$ = node[utils.SHADY_PREFIX + 'childNodes']; | ||
for (let i=0, l=c$.length, n; (i<l) && (n=c$[i]); i++) { | ||
for (let n=node[utils.SHADY_PREFIX + 'firstChild']; n; n = n[utils.SHADY_PREFIX + 'nextSibling']) { | ||
removeOwnerShadyRoot(n); | ||
} | ||
} | ||
|
@@ -187,9 +186,9 @@ export const NodePatches = utils.getOwnPropertyDescriptors({ | |
get textContent() { | ||
if (utils.isTrackingLogicalChildNodes(this)) { | ||
let tc = []; | ||
for (let i = 0, cn = this[utils.SHADY_PREFIX + 'childNodes'], c; (c = cn[i]); i++) { | ||
if (c.nodeType !== Node.COMMENT_NODE) { | ||
tc.push(c[utils.SHADY_PREFIX + 'textContent']); | ||
for (let n=this[utils.SHADY_PREFIX + 'firstChild']; n; n = n[utils.SHADY_PREFIX + 'nextSibling']) { | ||
if (n.nodeType !== Node.COMMENT_NODE) { | ||
tc.push(n[utils.SHADY_PREFIX + 'textContent']); | ||
} | ||
} | ||
return tc.join(''); | ||
|
@@ -307,7 +306,7 @@ export const NodePatches = utils.getOwnPropertyDescriptors({ | |
}); | ||
} | ||
// if a slot is added, must render containing root. | ||
if (this.localName === 'slot' || slotsAdded.length) { | ||
if (slotsAdded.length) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It was incorrect. This says "the node we're inserting into is a slot" and in this case a slot was not added. What it was meant to trap was |
||
if (slotsAdded.length) { | ||
ownerRoot._addSlots(slotsAdded); | ||
} | ||
|
@@ -447,9 +446,8 @@ export const NodePatches = utils.getOwnPropertyDescriptors({ | |
// been removed from the spec. | ||
// Make sure we do not do a deep clone on them for old browsers (IE11) | ||
if (deep && n.nodeType !== Node.ATTRIBUTE_NODE) { | ||
let c$ = this[utils.SHADY_PREFIX + 'childNodes']; | ||
for (let i=0, nc; i < c$.length; i++) { | ||
nc = c$[i][utils.SHADY_PREFIX + 'cloneNode'](true); | ||
for (let c=this[utils.SHADY_PREFIX + 'firstChild'], nc; c; c = c[utils.SHADY_PREFIX + 'nextSibling']) { | ||
nc = c[utils.SHADY_PREFIX + 'cloneNode'](true); | ||
n[utils.SHADY_PREFIX + 'appendChild'](nc); | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're keeping this change, let's add a comment for why... did something else patch the instance rather than the prototype?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, ShadyCSS patches this directly. Changing is path of least resistance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could change this though, correct? https://github.com/webcomponents/shadycss/blob/f377017e50f4d472a57ac224973f88b63a92f17e/src/style-placeholder.js#L54
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The "fast" (tearoff) native shim also patches the instance. So nevermind, let's just align on instance patching for now.