Skip to content

Commit 3dd0a5c

Browse files
committed
update record and playback to account for parent node missing when it will be added later
1 parent 33bd4eb commit 3dd0a5c

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"rrweb": patch
3+
---
4+
5+
updating record and playback side to account for mutations where a node is missing a parent but it gets added in a different iteration of the mutation

packages/rrweb/src/record/mutation.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,9 +383,11 @@ export default class MutationBuffer {
383383
}
384384

385385
for (const n of this.movedSet) {
386+
const parentNode = dom.parentNode(n);
386387
if (
387388
isParentRemoved(this.removesSubTreeCache, n, this.mirror) &&
388-
!this.movedSet.has(dom.parentNode(n)!)
389+
!this.movedSet.has(parentNode!) &&
390+
(!this.addedSet.has(parentNode!))
389391
) {
390392
continue;
391393
}

packages/rrweb/src/replay/index.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ import {
8282
getPositionsAndIndex,
8383
uniqueTextMutations,
8484
StyleSheetMirror,
85+
type ResolveTree
8586
} from '../utils';
8687
import getInjectStyleRules from './styles/inject-style';
8788
import './styles/style.css';
@@ -1703,6 +1704,18 @@ export class Replayer {
17031704
appendNode(mutation);
17041705
});
17051706

1707+
const nodeIdsToBeAdded = (resolveTrees: Array<ResolveTree>) => {
1708+
const ids = new Set();
1709+
for (const tree of resolveTrees) {
1710+
ids.add(tree.value.node.id);
1711+
if (tree.children && tree.children.length > 0) {
1712+
const res = nodeIdsToBeAdded(tree.children);
1713+
res.forEach(id => ids.add(id));
1714+
}
1715+
}
1716+
return ids;
1717+
};
1718+
17061719
const startTime = Date.now();
17071720
while (queue.length) {
17081721
// transform queue to resolve tree
@@ -1717,7 +1730,8 @@ export class Replayer {
17171730
}
17181731
for (const tree of resolveTrees) {
17191732
const parent = mirror.getNode(tree.value.parentId);
1720-
if (!parent) {
1733+
const ids = nodeIdsToBeAdded(resolveTrees);
1734+
if (!parent && !ids.has(tree.value.parentId)) {
17211735
this.debug(
17221736
'Drop resolve tree since there is no parent for the root node.',
17231737
tree,

packages/rrweb/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ export function polyfill(win = window) {
354354
}
355355
}
356356

357-
type ResolveTree = {
357+
export type ResolveTree = {
358358
value: addedNodeMutation;
359359
children: ResolveTree[];
360360
parent: ResolveTree | null;

0 commit comments

Comments
 (0)