From 9ed7e0921392a2ec89d79a5c15bd2b619854f1bf Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] check parentNode when calling insertBefore When add new nodes, we may use insertBefore API to insert node before its next sibling. But the sibling may not in the DOM tree at that moment if it was in the missing node map. --- src/replay/index.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/replay/index.ts b/src/replay/index.ts index 9f9dac2a..90296c48 100644 --- a/src/replay/index.ts +++ b/src/replay/index.ts @@ -271,9 +271,13 @@ export class Replayer { return; } - if (previous && previous.nextSibling) { + if ( + previous && + previous.nextSibling && + previous.nextSibling.parentNode + ) { parent.insertBefore(target, previous.nextSibling); - } else if (next) { + } else if (next && next.parentNode) { parent.insertBefore(target, next); } else { parent.appendChild(target);