From 4c0ced2ba186c5847119ea3371c94348e639e7d4 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] fix the add node condition --- src/replay/index.ts | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/src/replay/index.ts b/src/replay/index.ts index 296c62ea..fd922e43 100644 --- a/src/replay/index.ts +++ b/src/replay/index.ts @@ -224,16 +224,19 @@ export class Replayer { true, ) as Node; const parent = (mirror.getNode(mutation.parentId) as Node) as Element; + let previous: Node | null = null; + let next: Node | null = null; if (mutation.previousId) { - const previous = mirror.getNode(mutation.previousId) as Node; - if (previous) { - parent.insertBefore(target, previous.nextSibling); - } - } else if (mutation.nextId) { - const next = mirror.getNode(mutation.nextId) as Node; - if (next) { - parent.insertBefore(target, next); - } + previous = mirror.getNode(mutation.previousId) as Node; + } + if (mutation.nextId) { + next = mirror.getNode(mutation.nextId) as Node; + } + + if (previous && previous.nextSibling) { + parent.insertBefore(target, previous.nextSibling); + } else if (next) { + parent.insertBefore(target, next); } else { parent.appendChild(target); }