@chr33s/solarflare 0.0.11 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/diff-dom-streaming.ts +21 -8
package/package.json
CHANGED
|
@@ -63,7 +63,8 @@ async function updateNode(oldNode: Node, newNode: Node, walker: Walker) {
|
|
|
63
63
|
return walker[APPLY_TRANSITION](() => {
|
|
64
64
|
// oldNode may have been moved/removed by a previous batched mutation
|
|
65
65
|
if (oldNode.parentNode) {
|
|
66
|
-
oldNode.
|
|
66
|
+
const doc = oldNode.ownerDocument ?? document;
|
|
67
|
+
oldNode.parentNode.replaceChild(doc.importNode(newNode, true), oldNode);
|
|
67
68
|
}
|
|
68
69
|
});
|
|
69
70
|
}
|
|
@@ -75,17 +76,21 @@ async function updateNode(oldNode: Node, newNode: Node, walker: Walker) {
|
|
|
75
76
|
if (hasShadowRoot(oldNode as Element) && hasDsdTemplate(newNode as Element)) {
|
|
76
77
|
return walker[APPLY_TRANSITION](() => {
|
|
77
78
|
if (oldNode.parentNode) {
|
|
78
|
-
oldNode.
|
|
79
|
+
const doc = oldNode.ownerDocument ?? document;
|
|
80
|
+
oldNode.parentNode.replaceChild(doc.importNode(newNode, true), oldNode);
|
|
79
81
|
}
|
|
80
82
|
});
|
|
81
83
|
}
|
|
82
84
|
|
|
83
|
-
// Elements matching shouldReplaceNode are atomically replaced
|
|
84
|
-
//
|
|
85
|
+
// Elements matching shouldReplaceNode are atomically replaced.
|
|
86
|
+
// Use importNode to create the element in the target document context,
|
|
87
|
+
// avoiding adoptedCallback from firing on third-party web components.
|
|
85
88
|
if (walker.shouldReplaceNode?.(oldNode) || walker.shouldReplaceNode?.(newNode)) {
|
|
86
89
|
return walker[APPLY_TRANSITION](() => {
|
|
87
90
|
if (oldNode.parentNode) {
|
|
88
|
-
oldNode.
|
|
91
|
+
const doc = oldNode.ownerDocument ?? document;
|
|
92
|
+
const imported = doc.importNode(newNode, true);
|
|
93
|
+
oldNode.parentNode.replaceChild(imported, oldNode);
|
|
89
94
|
}
|
|
90
95
|
});
|
|
91
96
|
}
|
|
@@ -99,7 +104,8 @@ async function updateNode(oldNode: Node, newNode: Node, walker: Walker) {
|
|
|
99
104
|
}
|
|
100
105
|
} else {
|
|
101
106
|
const hasDocumentFragmentInside = newNode.nodeName === "TEMPLATE";
|
|
102
|
-
const
|
|
107
|
+
const doc = oldNode.ownerDocument ?? document;
|
|
108
|
+
const clonedNewNode = doc.importNode(newNode, hasDocumentFragmentInside);
|
|
103
109
|
while (oldNode.firstChild) clonedNewNode.appendChild(oldNode.firstChild);
|
|
104
110
|
// oldNode may have been moved/removed by a previous batched mutation
|
|
105
111
|
if (oldNode.parentNode) {
|
|
@@ -162,6 +168,11 @@ function setAttributes(oldAttributes: NamedNodeMap, newAttributes: NamedNodeMap)
|
|
|
162
168
|
}
|
|
163
169
|
}
|
|
164
170
|
|
|
171
|
+
/** Clone a node into the target document via importNode to avoid cross-document adoption. */
|
|
172
|
+
function cloneForDocument(node: Node, targetDoc: Document): Node {
|
|
173
|
+
return targetDoc.importNode(node, true);
|
|
174
|
+
}
|
|
175
|
+
|
|
165
176
|
/**
|
|
166
177
|
* Utility that will nodes childern to match another nodes children.
|
|
167
178
|
*/
|
|
@@ -252,7 +263,8 @@ async function setChildNodes(oldParent: Node, newParent: Node, walker: Walker) {
|
|
|
252
263
|
checkOld = oldNode;
|
|
253
264
|
oldNode = oldNode.nextSibling;
|
|
254
265
|
if (getKey(checkOld)) {
|
|
255
|
-
|
|
266
|
+
const targetDoc = oldParent.ownerDocument ?? document;
|
|
267
|
+
insertedNode = cloneForDocument(newNode, targetDoc);
|
|
256
268
|
if (shouldInsertImmediately(insertedNode!)) {
|
|
257
269
|
flushPendingInsertions();
|
|
258
270
|
walker[APPLY_TRANSITION](() => {
|
|
@@ -273,7 +285,8 @@ async function setChildNodes(oldParent: Node, newParent: Node, walker: Walker) {
|
|
|
273
285
|
await updateNode(checkOld, newNode, walker);
|
|
274
286
|
}
|
|
275
287
|
} else {
|
|
276
|
-
|
|
288
|
+
const targetDoc = oldParent.ownerDocument ?? document;
|
|
289
|
+
insertedNode = cloneForDocument(newNode, targetDoc);
|
|
277
290
|
if (shouldInsertImmediately(insertedNode!)) {
|
|
278
291
|
flushPendingInsertions();
|
|
279
292
|
walker[APPLY_TRANSITION](() => oldParent.appendChild(insertedNode!));
|