Skip to content

Commit

Permalink
Make sure this fix is only applied for LWC framework
Browse files Browse the repository at this point in the history
  • Loading branch information
YunFeng0817 committed Nov 21, 2023
1 parent 43a4fb1 commit 440ec80
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1078,16 +1078,18 @@ export function serializeNodeWithId(
keepIframeSrcFn,
};
let childNodes = Array.from(n.childNodes) as Node[];
childNodes = childNodes.filter(
// filter out nodes that are assigned to a slot other places.
(childN) => !(childN as HTMLElement).assignedSlot,
);

if ('assignedNodes' in n)
// If this is a slot element, add nodes that are assigned to this slot and treat them as normal children.
if (
n.nodeName === 'SLOT' &&
isShadowRoot(n.getRootNode()) &&
!isNativeShadowDom(n.getRootNode() as ShadowRoot) &&
!(n as HTMLSlotElement).hasAttribute('name')
)
// If this is a slot element in LWC framework, add nodes that are assigned to this slot and treat them as normal children.
childNodes = childNodes.concat(
Array.from((n as HTMLSlotElement).assignedNodes()),
);

for (const childN of Array.from(childNodes)) {
const serializedChildNode = serializeNodeWithId(childN, bypassOptions);
if (serializedChildNode) {
Expand Down

0 comments on commit 440ec80

Please sign in to comment.