Refactor to preclude the need for a continuous raf loop (#1328)
* Refactor to preclude the need for a continuous raf loop * Apply formatting changes * Create shadow-dom-unbusify.md --------- Co-authored-by: eoghanmurray <eoghanmurray@users.noreply.github.com>
This commit is contained in:
5
.changeset/shadow-dom-unbusify.md
Normal file
5
.changeset/shadow-dom-unbusify.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
---
|
||||||
|
'rrweb': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Refactor to preclude the need for a continuous raf loop running in the background which is related to shadowDom
|
||||||
@@ -5,19 +5,8 @@ import type MutationBuffer from './mutation';
|
|||||||
*/
|
*/
|
||||||
export default class ProcessedNodeManager {
|
export default class ProcessedNodeManager {
|
||||||
private nodeMap: WeakMap<Node, Set<MutationBuffer>> = new WeakMap();
|
private nodeMap: WeakMap<Node, Set<MutationBuffer>> = new WeakMap();
|
||||||
// Whether to continue RAF loop.
|
|
||||||
private loop = true;
|
|
||||||
|
|
||||||
constructor() {
|
private active = false;
|
||||||
this.periodicallyClear();
|
|
||||||
}
|
|
||||||
|
|
||||||
private periodicallyClear() {
|
|
||||||
requestAnimationFrame(() => {
|
|
||||||
this.clear();
|
|
||||||
if (this.loop) this.periodicallyClear();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public inOtherBuffer(node: Node, thisBuffer: MutationBuffer) {
|
public inOtherBuffer(node: Node, thisBuffer: MutationBuffer) {
|
||||||
const buffers = this.nodeMap.get(node);
|
const buffers = this.nodeMap.get(node);
|
||||||
@@ -27,15 +16,17 @@ export default class ProcessedNodeManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public add(node: Node, buffer: MutationBuffer) {
|
public add(node: Node, buffer: MutationBuffer) {
|
||||||
|
if (!this.active) {
|
||||||
|
this.active = true;
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
this.nodeMap = new WeakMap();
|
||||||
|
this.active = false;
|
||||||
|
});
|
||||||
|
}
|
||||||
this.nodeMap.set(node, (this.nodeMap.get(node) || new Set()).add(buffer));
|
this.nodeMap.set(node, (this.nodeMap.get(node) || new Set()).add(buffer));
|
||||||
}
|
}
|
||||||
|
|
||||||
private clear() {
|
|
||||||
this.nodeMap = new WeakMap();
|
|
||||||
}
|
|
||||||
|
|
||||||
public destroy() {
|
public destroy() {
|
||||||
// Stop the RAF loop.
|
// cleanup no longer needed
|
||||||
this.loop = false;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user