Fix: processed-node-manager is created even in the environment that doesn't need a recorder (#1186)
* Fix: processed-node-manager is created even in the environment that doesn't need a recorder * apply Justin's suggestion End the RAF loop when the recorder stops
This commit is contained in:
@@ -4,11 +4,7 @@ import {
|
||||
SlimDOMOptions,
|
||||
createMirror,
|
||||
} from 'rrweb-snapshot';
|
||||
import {
|
||||
initObservers,
|
||||
mutationBuffers,
|
||||
processedNodeManager,
|
||||
} from './observer';
|
||||
import { initObservers, mutationBuffers } from './observer';
|
||||
import {
|
||||
on,
|
||||
getWindowWidth,
|
||||
@@ -36,6 +32,7 @@ import { IframeManager } from './iframe-manager';
|
||||
import { ShadowDomManager } from './shadow-dom-manager';
|
||||
import { CanvasManager } from './observers/canvas/canvas-manager';
|
||||
import { StylesheetManager } from './stylesheet-manager';
|
||||
import ProcessedNodeManager from './processed-node-manager';
|
||||
import {
|
||||
callbackWrapper,
|
||||
registerErrorHandler,
|
||||
@@ -306,6 +303,8 @@ function record<T = eventWithTime>(
|
||||
});
|
||||
}
|
||||
|
||||
const processedNodeManager = new ProcessedNodeManager();
|
||||
|
||||
canvasManager = new CanvasManager({
|
||||
recordCanvas,
|
||||
mutationCb: wrappedCanvasMutationEmit,
|
||||
@@ -616,6 +615,7 @@ function record<T = eventWithTime>(
|
||||
}
|
||||
return () => {
|
||||
handlers.forEach((h) => h());
|
||||
processedNodeManager.destroy();
|
||||
recording = false;
|
||||
unregisterErrorHandler();
|
||||
};
|
||||
|
||||
@@ -41,7 +41,6 @@ import {
|
||||
selectionCallback,
|
||||
} from '@rrweb/types';
|
||||
import MutationBuffer from './mutation';
|
||||
import ProcessedNodeManager from './processed-node-manager';
|
||||
import { callbackWrapper } from './error-handler';
|
||||
|
||||
type WindowWithStoredMutationObserver = IWindow & {
|
||||
@@ -54,7 +53,6 @@ type WindowWithAngularZone = IWindow & {
|
||||
};
|
||||
|
||||
export const mutationBuffers: MutationBuffer[] = [];
|
||||
export const processedNodeManager = new ProcessedNodeManager();
|
||||
|
||||
// Event.path is non-standard and used in some older browsers
|
||||
type NonStandardEvent = Omit<Event, 'composedPath'> & {
|
||||
|
||||
@@ -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();
|
||||
@@ -13,7 +15,7 @@ export default class ProcessedNodeManager {
|
||||
private periodicallyClear() {
|
||||
requestAnimationFrame(() => {
|
||||
this.clear();
|
||||
this.periodicallyClear();
|
||||
if (this.loop) this.periodicallyClear();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -31,4 +33,9 @@ export default class ProcessedNodeManager {
|
||||
private clear() {
|
||||
this.nodeMap = new WeakMap();
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
// Stop the RAF loop.
|
||||
this.loop = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -574,6 +574,7 @@ export function getInputType(element: HTMLElement): Lowercase<string> | null {
|
||||
return element.hasAttribute('data-rr-is-password')
|
||||
? 'password'
|
||||
: element.hasAttribute('type')
|
||||
? (element.getAttribute('type')!.toLowerCase() as Lowercase<string>)
|
||||
? // eslint-disable-next-line @typescript-eslint/no-unnecessary-type-assertion, @typescript-eslint/no-non-null-assertion
|
||||
(element.getAttribute('type')!.toLowerCase() as Lowercase<string>)
|
||||
: null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user