Skip to content

Commit 0154a93

Browse files
committed
Utilize lastChild to avoid possibly crawling through hundreds of nodes
1 parent 79e0f7c commit 0154a93

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

packages/rrweb/src/record/mutation.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -226,19 +226,25 @@ export default class MutationBuffer {
226226
// not bad, just moved
227227
ancestorBad = false;
228228
}
229-
230229
if (!inDom(parentNode)) {
230+
// this check should overrule moved also
231231
ancestorBad = true;
232232
}
233233

234-
while (true) {
235-
nextSibling = n.nextSibling;
236-
if (this.addedSet.has(nextSibling as Node)) {
237-
// keep going as we can't serialize a node before it's next sibling (nextId requirement)
238-
n = nextSibling as Node;
239-
continue;
234+
if (this.addedSet.has(parentNode.lastChild as Node)) {
235+
// jump instead of crawling nextSibling to nextSibling
236+
n = parentNode.lastChild as Node;
237+
nextSibling = null;
238+
} else {
239+
while (true) {
240+
nextSibling = n.nextSibling;
241+
if (this.addedSet.has(nextSibling as Node)) {
242+
// keep going as we can't serialize a node before it's next sibling (nextId requirement)
243+
n = nextSibling as Node;
244+
continue;
245+
}
246+
break;
240247
}
241-
break;
242248
}
243249

244250
parentId = isShadowRoot(parentNode)

0 commit comments

Comments
 (0)