Skip to content

Commit

Permalink
Added record side logic to still add items in the movedSet if the par…
Browse files Browse the repository at this point in the history
…ent node is in the addedSet. On playback side when looping through resolveTrees added a check to see if a parent node was being added as part of another resolveTree in the mutation before dropping a resolveTree for parent not found
  • Loading branch information
mikeyagner committed Jan 6, 2025
1 parent e70ede9 commit 99193a3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/rrweb/src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -398,9 +398,11 @@ export default class MutationBuffer {
}

for (const n of this.movedSet) {
const parentNode = dom.parentNode(n);
if (
isParentRemoved(this.removesSubTreeCache, n, this.mirror) &&
!this.movedSet.has(dom.parentNode(n)!)
(!this.movedSet.has(parentNode!)) &&
(!this.addedSet.has(parentNode!))
) {
continue;
}
Expand Down
16 changes: 15 additions & 1 deletion packages/rrweb/src/replay/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ import {
getPositionsAndIndex,
uniqueTextMutations,
StyleSheetMirror,
type ResolveTree
} from '../utils';
import getInjectStyleRules from './styles/inject-style';
import './styles/style.css';
Expand Down Expand Up @@ -1707,6 +1708,18 @@ export class Replayer {
appendNode(mutation);
});

const nodeIdsToBeAdded = (resolveTrees: Array<ResolveTree>) => {
const ids = new Set();
for (const tree of resolveTrees) {
ids.add(tree.value.node.id);
if (tree.children && tree.children.length > 1) {
const res = nodeIdsToBeAdded(tree.children);
res.forEach(id => ids.add(id));
}
}
return ids;
};

const startTime = Date.now();
while (queue.length) {
// transform queue to resolve tree
Expand All @@ -1721,7 +1734,8 @@ export class Replayer {
}
for (const tree of resolveTrees) {
const parent = mirror.getNode(tree.value.parentId);
if (!parent) {
const ids = nodeIdsToBeAdded(resolveTrees);
if (!parent && !ids.has(tree.value.parentId)) {
this.debug(
'Drop resolve tree since there is no parent for the root node.',
tree,
Expand Down
2 changes: 1 addition & 1 deletion packages/rrweb/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export function polyfill(win = window) {
}
}

type ResolveTree = {
export type ResolveTree = {
value: addedNodeMutation;
children: ResolveTree[];
parent: ResolveTree | null;
Expand Down

0 comments on commit 99193a3

Please sign in to comment.