fix: bug when handling shadow doms (#1041)

On the website https://mixpanel.com/project/2195193/view/139237/app/dashboards#id=3679845, the bottom chart makes the recorder crash (infinite loop)
This commit is contained in:
MF
2026-04-01 12:00:00 +08:00
committed by GitHub
parent 422591890e
commit 25db99495c

View File

@@ -393,15 +393,20 @@ export default class MutationBuffer {
} }
// nextId !== -1 && parentId === -1 This branch can happen if the node is the child of shadow root // nextId !== -1 && parentId === -1 This branch can happen if the node is the child of shadow root
else { else {
const nodeInShadowDom = _node.value; const unhandledNode = _node.value;
// Get the host of the shadow dom and treat it as parent node. // If the node is the direct child of a shadow root, we treat the shadow host as its parent node.
const shadowHost: Element | null = nodeInShadowDom.getRootNode if (
? (nodeInShadowDom.getRootNode() as ShadowRoot)?.host unhandledNode.parentNode &&
: null; unhandledNode.parentNode.nodeType ===
const parentId = this.mirror.getId(shadowHost); Node.DOCUMENT_FRAGMENT_NODE
if (parentId !== -1) { ) {
node = _node; const shadowHost = (unhandledNode.parentNode as ShadowRoot)
break; .host;
const parentId = this.mirror.getId(shadowHost);
if (parentId !== -1) {
node = _node;
break;
}
} }
} }
} }