Skip to content

Commit

Permalink
optimization for when maskAllText is false rrweb-io#1096
Browse files Browse the repository at this point in the history
  • Loading branch information
mdellanoce committed Nov 7, 2023
1 parent 2e37a31 commit 08ac4b0
Showing 1 changed file with 32 additions and 13 deletions.
45 changes: 32 additions & 13 deletions packages/rrweb-snapshot/src/snapshot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -363,21 +363,40 @@ export function needMaskingText(
: node.parentElement;
if (el === null) return false;

const unmaskDistance = distanceToMatch(
el,
createMatchPredicate(unmaskTextClass, unmaskTextSelector),
);

let maskDistance = -1;
if (maskAllText && unmaskDistance < 0) {
return true;
}
let unmaskDistance = -1;

maskDistance = distanceToMatch(
el,
createMatchPredicate(maskTextClass, maskTextSelector),
unmaskDistance >= 0 ? unmaskDistance : Infinity,
);
if (maskAllText) {
unmaskDistance = distanceToMatch(
el,
createMatchPredicate(unmaskTextClass, unmaskTextSelector),
);

if (unmaskDistance < 0) {
return true;
}

maskDistance = distanceToMatch(
el,
createMatchPredicate(maskTextClass, maskTextSelector),
unmaskDistance >= 0 ? unmaskDistance : Infinity,
);
} else {
maskDistance = distanceToMatch(
el,
createMatchPredicate(maskTextClass, maskTextSelector),
);

if (maskDistance < 0) {
return false;
}

unmaskDistance = distanceToMatch(
el,
createMatchPredicate(unmaskTextClass, unmaskTextSelector),
maskDistance >= 0 ? maskDistance : Infinity,
);
}

return maskDistance >= 0
? unmaskDistance >= 0
Expand Down

0 comments on commit 08ac4b0

Please sign in to comment.