@chr33s/solarflare 0.0.11 → 0.0.12

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@chr33s/solarflare",
3
- "version": "0.0.11",
3
+ "version": "0.0.12",
4
4
  "license": "MIT",
5
5
  "repository": {
6
6
  "type": "git",
@@ -80,12 +80,15 @@ async function updateNode(oldNode: Node, newNode: Node, walker: Walker) {
80
80
  });
81
81
  }
82
82
 
83
- // Elements matching shouldReplaceNode are atomically replaced to avoid
84
- // triggering adoptedCallback on third-party web components (e.g. Polaris).
83
+ // Elements matching shouldReplaceNode are atomically replaced.
84
+ // Use importNode to create the element in the target document context,
85
+ // avoiding adoptedCallback from firing on third-party web components.
85
86
  if (walker.shouldReplaceNode?.(oldNode) || walker.shouldReplaceNode?.(newNode)) {
86
87
  return walker[APPLY_TRANSITION](() => {
87
88
  if (oldNode.parentNode) {
88
- oldNode.parentNode.replaceChild(newNode.cloneNode(true), oldNode);
89
+ const doc = oldNode.ownerDocument ?? document;
90
+ const imported = doc.importNode(newNode, true);
91
+ oldNode.parentNode.replaceChild(imported, oldNode);
89
92
  }
90
93
  });
91
94
  }
@@ -162,6 +165,17 @@ function setAttributes(oldAttributes: NamedNodeMap, newAttributes: NamedNodeMap)
162
165
  }
163
166
  }
164
167
 
168
+ /**
169
+ * Clone a node, using importNode for elements matching shouldReplaceNode
170
+ * to avoid triggering adoptedCallback on third-party web components.
171
+ */
172
+ function cloneForDocument(node: Node, targetDoc: Document, walker: Walker): Node {
173
+ if (walker.shouldReplaceNode?.(node)) {
174
+ return targetDoc.importNode(node, true);
175
+ }
176
+ return node.cloneNode(true);
177
+ }
178
+
165
179
  /**
166
180
  * Utility that will nodes childern to match another nodes children.
167
181
  */
@@ -252,7 +266,8 @@ async function setChildNodes(oldParent: Node, newParent: Node, walker: Walker) {
252
266
  checkOld = oldNode;
253
267
  oldNode = oldNode.nextSibling;
254
268
  if (getKey(checkOld)) {
255
- insertedNode = newNode.cloneNode(true);
269
+ const targetDoc = oldParent.ownerDocument ?? document;
270
+ insertedNode = cloneForDocument(newNode, targetDoc, walker);
256
271
  if (shouldInsertImmediately(insertedNode!)) {
257
272
  flushPendingInsertions();
258
273
  walker[APPLY_TRANSITION](() => {
@@ -273,7 +288,8 @@ async function setChildNodes(oldParent: Node, newParent: Node, walker: Walker) {
273
288
  await updateNode(checkOld, newNode, walker);
274
289
  }
275
290
  } else {
276
- insertedNode = newNode.cloneNode(true);
291
+ const targetDoc = oldParent.ownerDocument ?? document;
292
+ insertedNode = cloneForDocument(newNode, targetDoc, walker);
277
293
  if (shouldInsertImmediately(insertedNode!)) {
278
294
  flushPendingInsertions();
279
295
  walker[APPLY_TRANSITION](() => oldParent.appendChild(insertedNode!));