Skip to content

Commit

Permalink
perf: improve blocked and masking logic checks
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasBa committed Jul 18, 2024
1 parent 93e65f3 commit d0d211a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
17 changes: 8 additions & 9 deletions packages/rrdom/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -345,11 +345,7 @@ export class Mirror implements IMirror<RRNode> {

getId(n: RRNode | undefined | null): number {
if (!n) return -1;

const id = this.getMeta(n)?.id;

// if n is not a serialized Node, use -1 as its id.
return id ?? -1;
return this.getMeta(n)?.id ?? -1;
}

getNode(id: number): RRNode | null {
Expand All @@ -367,11 +363,14 @@ export class Mirror implements IMirror<RRNode> {
// removes the node from idNodeMap
// doesn't remove the node from nodeMetaMap
removeNodeFromMap(n: RRNode) {
const id = this.getId(n);
this.idNodeMap.delete(id);
const queue = [n];
while (queue.length > 0) {
const n = queue.pop()!;

Check warning on line 368 in packages/rrdom/src/index.ts

View workflow job for this annotation

GitHub Actions / ESLint Report Analysis

packages/rrdom/src/index.ts#L368

[@typescript-eslint/no-non-null-assertion] Forbidden non-null assertion.
this.idNodeMap.delete(this.getId(n));

if (n.childNodes) {
n.childNodes.forEach((childNode) => this.removeNodeFromMap(childNode));
for(let i = 0; i < n.childNodes.length; i++) {
queue.push(n.childNodes[i]);
}
}
}
has(id: number): boolean {
Expand Down
18 changes: 4 additions & 14 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -340,26 +340,16 @@ export function needMaskingText(
} else {
el = node.parentElement;
}
try {
if (typeof maskTextClass === 'string') {
if (checkAncestors) {
if (el.closest(`.${maskTextClass}`)) return true;
} else {
if (el.classList.contains(maskTextClass)) return true;
}
if (el.classList.contains(maskTextClass)) return true;
if (checkAncestors && el.matches(`.${maskTextClass} *`)) return true;
} else {
if (classMatchesRegex(el, maskTextClass, checkAncestors)) return true;
}
if (maskTextSelector) {
if (checkAncestors) {
if (el.closest(maskTextSelector)) return true;
} else {
if (el.matches(maskTextSelector)) return true;
}
if (el.matches(maskTextSelector)) return true;
if (checkAncestors && el.matches(`${maskTextSelector} *`)) return true;
}
} catch (e) {
//
}
return false;
}

Expand Down

0 comments on commit d0d211a

Please sign in to comment.