Skip to content

Commit

Permalink
apply Justin's suggestion
Browse files Browse the repository at this point in the history
End the RAF loop when the recorder stops
  • Loading branch information
YunFeng0817 committed Mar 23, 2023
1 parent 26201a3 commit 5f4bd8a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions packages/rrweb/src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -615,6 +615,7 @@ function record<T = eventWithTime>(
}
return () => {
handlers.forEach((h) => h());
processedNodeManager.destroy();
recording = false;
unregisterErrorHandler();
};
Expand Down
9 changes: 8 additions & 1 deletion packages/rrweb/src/record/processed-node-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import type MutationBuffer from './mutation';
*/
export default class ProcessedNodeManager {
private nodeMap: WeakMap<Node, Set<MutationBuffer>> = new WeakMap();
// Whether to continue RAF loop.
private loop = true;

constructor() {
this.periodicallyClear();
Expand All @@ -13,7 +15,7 @@ export default class ProcessedNodeManager {
private periodicallyClear() {
requestAnimationFrame(() => {
this.clear();
this.periodicallyClear();
if (this.loop) this.periodicallyClear();
});
}

Expand All @@ -31,4 +33,9 @@ export default class ProcessedNodeManager {
private clear() {
this.nodeMap = new WeakMap();
}

public destroy() {
// Stop the RAF loop.
this.loop = false;
}
}

0 comments on commit 5f4bd8a

Please sign in to comment.