Skip to content

Commit

Permalink
Extend the suppression of warnings to take into account anscestors (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
eoghanmurray authored Mar 18, 2023
1 parent e0f862b commit a82a3b4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
5 changes: 5 additions & 0 deletions .changeset/proud-experts-jam.md
Original file line number Diff line number Diff line change
@@ -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
16 changes: 11 additions & 5 deletions packages/rrweb/src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit a82a3b4

Please sign in to comment.