@posthog/rrweb-player 0.0.24 → 0.0.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -4756,6 +4756,12 @@ function buildNodeWithSN(n2, options) {
4756
4756
  } else {
4757
4757
  node2.appendChild(childNode);
4758
4758
  }
4759
+ } else if (n2.type === NodeType$1$1.Document && childN.type === NodeType$1$1.DocumentType) {
4760
+ if (node2.firstChild && node2.firstChild.nodeType === 1) {
4761
+ node2.insertBefore(childNode, node2.firstChild);
4762
+ } else {
4763
+ node2.appendChild(childNode);
4764
+ }
4759
4765
  } else {
4760
4766
  node2.appendChild(childNode);
4761
4767
  }
@@ -11735,6 +11741,11 @@ class Replayer {
11735
11741
  __publicField2(this, "lastSelectionData", null);
11736
11742
  __publicField2(this, "constructedStyleMutations", []);
11737
11743
  __publicField2(this, "adoptedStyleSheets", []);
11744
+ __publicField2(this, "emitterHandlers", []);
11745
+ __publicField2(this, "serviceSubscription");
11746
+ __publicField2(this, "speedServiceSubscription");
11747
+ __publicField2(this, "timeouts", /* @__PURE__ */ new Set());
11748
+ __publicField2(this, "styleSheetLoadListeners", /* @__PURE__ */ new Map());
11738
11749
  __publicField2(this, "handleResize", (dimension) => {
11739
11750
  this.iframe.style.display = "inherit";
11740
11751
  for (const el of [this.mouseTail, this.iframe]) {
@@ -11894,12 +11905,12 @@ class Replayer {
11894
11905
  this.handleResize = this.handleResize.bind(this);
11895
11906
  this.getCastFn = this.getCastFn.bind(this);
11896
11907
  this.applyEventsSynchronously = this.applyEventsSynchronously.bind(this);
11897
- this.emitter.on(ReplayerEvents.Resize, this.handleResize);
11908
+ this.addEmitterHandler(ReplayerEvents.Resize, this.handleResize);
11898
11909
  this.setupDom();
11899
11910
  for (const plugin of this.config.plugins || []) {
11900
11911
  if (plugin.getMirror) plugin.getMirror({ nodeMirror: this.mirror });
11901
11912
  }
11902
- this.emitter.on(ReplayerEvents.Flush, () => {
11913
+ const flushHandler = () => {
11903
11914
  if (this.usingVirtualDom) {
11904
11915
  const replayerHandler = {
11905
11916
  mirror: this.mirror,
@@ -11995,13 +12006,15 @@ class Replayer {
11995
12006
  this.applySelection(this.lastSelectionData);
11996
12007
  this.lastSelectionData = null;
11997
12008
  }
11998
- });
11999
- this.emitter.on(ReplayerEvents.PlayBack, () => {
12009
+ };
12010
+ this.addEmitterHandler(ReplayerEvents.Flush, flushHandler);
12011
+ const playBackHandler = () => {
12000
12012
  this.firstFullSnapshot = null;
12001
12013
  this.mirror.reset();
12002
12014
  this.styleMirror.reset();
12003
12015
  this.mediaManager.reset();
12004
- });
12016
+ };
12017
+ this.addEmitterHandler(ReplayerEvents.PlayBack, playBackHandler);
12005
12018
  const timer = new Timer([], {
12006
12019
  speed: this.config.speed
12007
12020
  });
@@ -12025,7 +12038,7 @@ class Replayer {
12025
12038
  }
12026
12039
  );
12027
12040
  this.service.start();
12028
- this.service.subscribe((state) => {
12041
+ this.serviceSubscription = this.service.subscribe((state) => {
12029
12042
  this.emitter.emit(ReplayerEvents.StateChange, {
12030
12043
  player: state
12031
12044
  });
@@ -12035,7 +12048,7 @@ class Replayer {
12035
12048
  timer
12036
12049
  });
12037
12050
  this.speedService.start();
12038
- this.speedService.subscribe((state) => {
12051
+ this.speedServiceSubscription = this.speedService.subscribe((state) => {
12039
12052
  this.emitter.emit(ReplayerEvents.StateChange, {
12040
12053
  speed: state
12041
12054
  });
@@ -12055,7 +12068,7 @@ class Replayer {
12055
12068
  );
12056
12069
  if (firstMeta) {
12057
12070
  const { width, height } = firstMeta.data;
12058
- setTimeout(() => {
12071
+ this.addTimeout(() => {
12059
12072
  this.emitter.emit(ReplayerEvents.Resize, {
12060
12073
  width,
12061
12074
  height
@@ -12063,7 +12076,7 @@ class Replayer {
12063
12076
  }, 0);
12064
12077
  }
12065
12078
  if (firstFullsnapshot) {
12066
- setTimeout(() => {
12079
+ this.addTimeout(() => {
12067
12080
  var _a2;
12068
12081
  if (this.firstFullSnapshot) {
12069
12082
  return;
@@ -12092,6 +12105,24 @@ class Replayer {
12092
12105
  this.emitter.off(event, handler);
12093
12106
  return this;
12094
12107
  }
12108
+ /**
12109
+ * Track emitter handlers for cleanup
12110
+ */
12111
+ addEmitterHandler(event, handler) {
12112
+ this.emitter.on(event, handler);
12113
+ this.emitterHandlers.push({ event, handler });
12114
+ }
12115
+ /**
12116
+ * Track timeouts for cleanup
12117
+ */
12118
+ addTimeout(callback, delay) {
12119
+ const timeout = setTimeout(() => {
12120
+ this.timeouts.delete(timeout);
12121
+ callback();
12122
+ }, delay);
12123
+ this.timeouts.add(timeout);
12124
+ return timeout;
12125
+ }
12095
12126
  setConfig(config) {
12096
12127
  Object.keys(config).forEach((key) => {
12097
12128
  config[key];
@@ -12194,10 +12225,31 @@ class Replayer {
12194
12225
  * Memory occupation can be released by removing all references to this replayer.
12195
12226
  */
12196
12227
  destroy() {
12228
+ var _a2, _b2;
12229
+ if (!this.wrapper || !this.wrapper.parentNode) {
12230
+ return;
12231
+ }
12197
12232
  this.pause();
12233
+ this.emitterHandlers.forEach(({ event, handler }) => {
12234
+ this.emitter.off(event, handler);
12235
+ });
12236
+ this.emitterHandlers = [];
12237
+ (_a2 = this.serviceSubscription) == null ? void 0 : _a2.unsubscribe();
12238
+ (_b2 = this.speedServiceSubscription) == null ? void 0 : _b2.unsubscribe();
12239
+ this.serviceSubscription = void 0;
12240
+ this.speedServiceSubscription = void 0;
12241
+ this.timeouts.forEach((timeout) => clearTimeout(timeout));
12242
+ this.timeouts.clear();
12243
+ this.styleSheetLoadListeners.forEach((handler, element2) => {
12244
+ element2.removeEventListener("load", handler);
12245
+ });
12246
+ this.styleSheetLoadListeners.clear();
12247
+ this.imageMap.clear();
12248
+ this.canvasEventMap.clear();
12198
12249
  this.mirror.reset();
12199
12250
  this.styleMirror.reset();
12200
12251
  this.mediaManager.reset();
12252
+ this.resetCache();
12201
12253
  this.config.root.removeChild(this.wrapper);
12202
12254
  this.emitter.emit(ReplayerEvents.Destroy);
12203
12255
  }