From 86286ddb94ad0afb3a13677df0a83e1903dd25bc Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Fri, 23 Nov 2018 18:08:37 +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);