* Add test cases for bugs * Fix shadow dom recording When moving an element containing shadow dom When adding an element to shadow dom before its attached to the dom * Apply formatting changes * Refactor in dom checking code * Nodes don't get processed in more than one mutation buffer * Constrain node mutations to one mutation buffer per request animation frame * Make tests less flaky under heavy load * Apply suggestions from code review * Update packages/rrweb-snapshot/test/rebuild.test.ts * Remove unused nodeSet Co-authored-by: Yun Feng <yun.feng0817@gmail.com>
35 lines
864 B
TypeScript
35 lines
864 B
TypeScript
import type MutationBuffer from './mutation';
|
|
|
|
/**
|
|
* Keeps a log of nodes that could show up in multiple mutation buffer but shouldn't be handled twice.
|
|
*/
|
|
export default class ProcessedNodeManager {
|
|
private nodeMap: WeakMap<Node, Set<MutationBuffer>> = new WeakMap();
|
|
|
|
constructor() {
|
|
this.periodicallyClear();
|
|
}
|
|
|
|
private periodicallyClear() {
|
|
requestAnimationFrame(() => {
|
|
this.clear();
|
|
this.periodicallyClear();
|
|
});
|
|
}
|
|
|
|
public inOtherBuffer(node: Node, thisBuffer: MutationBuffer) {
|
|
const buffers = this.nodeMap.get(node);
|
|
return (
|
|
buffers && Array.from(buffers).some((buffer) => buffer !== thisBuffer)
|
|
);
|
|
}
|
|
|
|
public add(node: Node, buffer: MutationBuffer) {
|
|
this.nodeMap.set(node, (this.nodeMap.get(node) || new Set()).add(buffer));
|
|
}
|
|
|
|
private clear() {
|
|
this.nodeMap = new WeakMap();
|
|
}
|
|
}
|