sitepong 0.2.11 → 0.2.12

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.
@@ -732,6 +732,12 @@ interface WatchtowerConfig {
732
732
  * you give the SDK's identify() so users line up across pipelines.
733
733
  */
734
734
  distinctId?: string;
735
+ /**
736
+ * Idle grace in ms: reopening the app within this window of backgrounding
737
+ * resumes the same session; beyond it, a new (linked) session starts.
738
+ * Default 30_000 (30s). Lower it in tests to exercise session rolling.
739
+ */
740
+ sessionGraceMs?: number;
735
741
  }
736
742
  /**
737
743
  * Start the shared native capture engine for React Native. Idempotent.
@@ -3580,6 +3580,21 @@ var Recorder = class {
3580
3580
  emit(t, m) {
3581
3581
  this.stream.push({ t, m });
3582
3582
  }
3583
+ /**
3584
+ * Reinitialize for a brand-new session — fresh id space, empty tree/stream,
3585
+ * no pending outcome windows. The capture engine calls this when it rolls to
3586
+ * a new session (app reopened after the idle grace) so the new stream begins
3587
+ * with a clean full snapshot rather than diffing against the prior session's
3588
+ * tree (which would leave the new session missing its initial creates).
3589
+ */
3590
+ reset() {
3591
+ this.mirror = new Mirror();
3592
+ this.index = emptyIndex();
3593
+ this.analyzer = new InteractionAnalyzer();
3594
+ this.stream = [];
3595
+ this.pending = [];
3596
+ this.viewport = { w: 0, h: 0 };
3597
+ }
3583
3598
  setViewport(w, h, t) {
3584
3599
  this.viewport = { w, h };
3585
3600
  this.emit(t, [5, w, h]);
@@ -3993,6 +4008,7 @@ var StructuralCapture = class {
3993
4008
  this.scrollOffsets.clear();
3994
4009
  this.overloadSkip = 0;
3995
4010
  this.explicitRoot = null;
4011
+ this.recorder.reset();
3996
4012
  const { width, height } = reactNative.Dimensions.get("window");
3997
4013
  this.recorder.setViewport(Math.round(width), Math.round(height), 0);
3998
4014
  this.sampleTimer = setInterval(() => this.sample(), cfg.sampleIntervalMs ?? 120);
@@ -4720,7 +4736,8 @@ function startWatchtower(config) {
4720
4736
  projectId: config.projectId,
4721
4737
  endpoint: config.endpoint,
4722
4738
  sampleRate: config.sampleRate ?? 0.1,
4723
- platform: config.platform ?? "react-native-ios"
4739
+ platform: config.platform ?? "react-native-ios",
4740
+ sessionGraceMs: config.sessionGraceMs ?? 3e4
4724
4741
  });
4725
4742
  started = true;
4726
4743
  if (config.distinctId) setWatchtowerUser(config.distinctId);
@@ -4780,11 +4797,32 @@ function StructuralCaptureProvider({ children, ...cfg }) {
4780
4797
  React2.useEffect(() => {
4781
4798
  let cancelled = false;
4782
4799
  let poll = null;
4800
+ let adoptTimer = null;
4801
+ let currentSid;
4802
+ let readopting = false;
4783
4803
  const begin = (sessionId) => {
4784
4804
  if (cancelled) return;
4805
+ currentSid = sessionId;
4785
4806
  structuralCapture.start({ ...cfgRef.current, sessionId });
4786
4807
  structuralCapture.setRootInstance(rootRef.current);
4787
4808
  };
4809
+ const readopt = async (sessionId) => {
4810
+ if (cancelled || readopting) return;
4811
+ readopting = true;
4812
+ try {
4813
+ await structuralCapture.stop();
4814
+ begin(sessionId);
4815
+ } finally {
4816
+ readopting = false;
4817
+ }
4818
+ };
4819
+ const watchForRoll = () => {
4820
+ adoptTimer = setInterval(() => {
4821
+ if (cancelled || readopting) return;
4822
+ const wt = getWatchtowerSessionId();
4823
+ if (wt && wt !== currentSid) void readopt(wt);
4824
+ }, 1e3);
4825
+ };
4788
4826
  const explicit = cfgRef.current.sessionId;
4789
4827
  if (explicit) {
4790
4828
  begin(explicit);
@@ -4793,8 +4831,16 @@ function StructuralCaptureProvider({ children, ...cfg }) {
4793
4831
  const resolve = () => {
4794
4832
  if (cancelled) return;
4795
4833
  const wt = getWatchtowerSessionId();
4796
- if (wt) return begin(wt);
4797
- if (++tries >= 25) return begin(void 0);
4834
+ if (wt) {
4835
+ begin(wt);
4836
+ watchForRoll();
4837
+ return;
4838
+ }
4839
+ if (++tries >= 25) {
4840
+ begin(void 0);
4841
+ watchForRoll();
4842
+ return;
4843
+ }
4798
4844
  poll = setTimeout(resolve, 200);
4799
4845
  };
4800
4846
  resolve();
@@ -4802,6 +4848,7 @@ function StructuralCaptureProvider({ children, ...cfg }) {
4802
4848
  return () => {
4803
4849
  cancelled = true;
4804
4850
  if (poll) clearTimeout(poll);
4851
+ if (adoptTimer) clearInterval(adoptTimer);
4805
4852
  void structuralCapture.stop();
4806
4853
  };
4807
4854
  }, []);