From 65ef257d33bddf922bebe6fdd82260e8e671b7b2 Mon Sep 17 00:00:00 2001 From: Eoghan Murray Date: Wed, 1 Apr 2026 12:00:00 +0800 Subject: [PATCH] Extend the suppression of warnings to take into account anscestors (#1145) * Extend the suppression of warnings to take account that a prior removal may not have been against the immediate parent of a subsequent removal, but rather some anscestor * Create proud-experts-jam.md * Apply formatting changes --- .changeset/proud-experts-jam.md | 5 +++++ packages/rrweb/src/replay/index.ts | 16 +++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) create mode 100644 .changeset/proud-experts-jam.md diff --git a/.changeset/proud-experts-jam.md b/.changeset/proud-experts-jam.md new file mode 100644 index 00000000..fa60839b --- /dev/null +++ b/.changeset/proud-experts-jam.md @@ -0,0 +1,5 @@ +--- +'rrweb': patch +--- + +For a mutation which removes a node, reduce the number of spurious warnings to take into account that an anscestor (rather than just a parent) may have been just removed diff --git a/packages/rrweb/src/replay/index.ts b/packages/rrweb/src/replay/index.ts index 52762102..91ee9d5f 100644 --- a/packages/rrweb/src/replay/index.ts +++ b/packages/rrweb/src/replay/index.ts @@ -1371,14 +1371,20 @@ export class Replayer { const mirror = this.usingVirtualDom ? this.virtualDom.mirror : this.mirror; type TNode = typeof mirror extends Mirror ? Node : RRNode; + d.removes = d.removes.filter((mutation) => { + // warn of absence from mirror before we start applying each removal + // as earlier removals could remove a tree that includes a later removal + if (!mirror.getNode(mutation.id)) { + this.warnNodeNotFound(d, mutation.id); + return false; + } + return true; + }); d.removes.forEach((mutation) => { const target = mirror.getNode(mutation.id); if (!target) { - if (d.removes.find((r) => r.id === mutation.parentId)) { - // no need to warn, parent was already removed - return; - } - return this.warnNodeNotFound(d, mutation.id); + // no need to warn here, an ancestor may have already been removed + return; } let parent: Node | null | ShadowRoot | RRNode = mirror.getNode( mutation.parentId,