Skip to content

Commit 79e0f7c

Browse files
committed
Satisfy typescript which could be smarter here ... we can guarantee that if a possibly null node is in e.g. this.addedSet, then it is indeed not null. Similarly if this.addedSet.size is non zero, then we can pop confidently
1 parent 4babf3c commit 79e0f7c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

packages/rrweb/src/record/mutation.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -195,24 +195,24 @@ export default class MutationBuffer {
195195
let ancestorBad = false;
196196
const missingParents = new Set<Node>();
197197
while (this.addedSet.size) {
198-
if (n !== null && this.addedSet.has(n.previousSibling)) {
198+
if (n !== null && this.addedSet.has(n.previousSibling as Node)) {
199199
// reuse parentNode, parentId, ancestorBad
200200
nextSibling = n; // n is a good next sibling
201-
n = n.previousSibling;
201+
n = n.previousSibling as Node;
202202
} else {
203-
n = this.addedSet.values().next().value; // pop
203+
n = this.addedSet.values().next().value as Node; // pop
204204

205205
while (true) {
206206
parentNode = dom.parentNode(n);
207-
if (this.addedSet.has(parentNode)) {
207+
if (this.addedSet.has(parentNode as Node)) {
208208
// start at top of added tree so as not to serialize children before their parents (parentId requirement)
209-
n = parentNode;
209+
n = parentNode as Node;
210210
continue;
211211
}
212212
break;
213213
}
214214

215-
if (missingParents.has(parentNode)) {
215+
if (missingParents.has(parentNode as Node)) {
216216
parentNode = null;
217217
} else if (parentNode) {
218218
// we have a new parentNode for a 'row' of DOM children
@@ -233,9 +233,9 @@ export default class MutationBuffer {
233233

234234
while (true) {
235235
nextSibling = n.nextSibling;
236-
if (this.addedSet.has(nextSibling)) {
236+
if (this.addedSet.has(nextSibling as Node)) {
237237
// keep going as we can't serialize a node before it's next sibling (nextId requirement)
238-
n = nextSibling;
238+
n = nextSibling as Node;
239239
continue;
240240
}
241241
break;
@@ -258,7 +258,7 @@ export default class MutationBuffer {
258258

259259
this.addedSet.delete(n); // don't re-iterate
260260

261-
if (!parentNode || parentId === -1) {
261+
if (!parentNode || parentId === -1 || parentId === null) {
262262
missingParents.add(n); // ensure any added child nodes can also early-out
263263
continue;
264264
} else if (ancestorBad) {
@@ -316,9 +316,12 @@ export default class MutationBuffer {
316316
currentN as HTMLLinkElement,
317317
);
318318
}
319-
if (hasShadowRoot(n)) {
319+
if (hasShadowRoot(n as Node)) {
320320
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
321-
this.shadowDomManager.addShadowRoot(dom.shadowRoot(n)!, this.doc);
321+
this.shadowDomManager.addShadowRoot(
322+
dom.shadowRoot(n as Node)!,
323+
this.doc,
324+
);
322325
}
323326
},
324327
onIframeLoad: (iframe, childSn) => {

0 commit comments

Comments
 (0)