Skip to content

Commit

Permalink
Merge pull request #17 from pendo-io/md-102293
Browse files Browse the repository at this point in the history
use native requestAnimationFrame in ProcessedNodeManager
  • Loading branch information
brec-c authored May 28, 2024
2 parents ea99b59 + 8d291e7 commit bea64d2
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion packages/rrweb/src/record/processed-node-manager.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type MutationBuffer from './mutation';
import { getNative } from 'rrweb-snapshot';

/**
* Keeps a log of nodes that could show up in multiple mutation buffer but shouldn't be handled twice.
Expand All @@ -7,13 +8,17 @@ export default class ProcessedNodeManager {
private nodeMap: WeakMap<Node, Set<MutationBuffer>> = new WeakMap();
// Whether to continue RAF loop.
private loop = true;
private nativeRAF;

constructor() {
this.nativeRAF = getNative<typeof requestAnimationFrame>(
'requestAnimationFrame',
).bind(window);
this.periodicallyClear();
}

private periodicallyClear() {
requestAnimationFrame(() => {
this.nativeRAF(() => {
this.clear();
if (this.loop) this.periodicallyClear();
});
Expand Down

0 comments on commit bea64d2

Please sign in to comment.