Skip to content

Commit

Permalink
Use the .closest method to transfer recursive parent class checking i…
Browse files Browse the repository at this point in the history
…nto the browser engine for an expected performance improvement

https://developer.mozilla.org/en-US/docs/Web/API/Element/closest available on all modern browsers
  • Loading branch information
eoghanmurray committed Feb 21, 2022
1 parent 94fa6b3 commit 2fb27a3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion packages/rrweb/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ export function isBlocked(node: Node | null, blockClass: blockClass): boolean {
if (node.nodeType === node.ELEMENT_NODE) {
let needBlock = false;
if (typeof blockClass === 'string') {
needBlock = (node as HTMLElement).classList.contains(blockClass);
if ((node as HTMLElement).closest !== undefined) {
return (node as HTMLElement).closest('.' + blockClass) !== null;
} else {
needBlock = (node as HTMLElement).classList.contains(blockClass);
}
} else {
(node as HTMLElement).classList.forEach((className) => {
if (blockClass.test(className)) {
Expand Down

0 comments on commit 2fb27a3

Please sign in to comment.