@openreplay/tracker 18.0.16 → 18.0.17-beta.0

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.
package/dist/cjs/index.js CHANGED
@@ -2217,22 +2217,32 @@ class Logger {
2217
2217
  }
2218
2218
 
2219
2219
  const SECOND = 1000;
2220
- function processMapInBatches(map, batchSize, processBatchCallback) {
2220
+ function processMapInBatches(map, batchSize, processBatchCallback,
2221
+ // reports the pending inter-batch timeout so the caller can cancel it on stop()
2222
+ onScheduled,
2223
+ // called once the whole map has been walked (or there was nothing to walk)
2224
+ onComplete) {
2221
2225
  const iterator = map.entries();
2222
2226
  function processNextBatch() {
2223
- const batch = [];
2227
+ let processed = 0;
2224
2228
  let result = iterator.next();
2225
- while (!result.done && batch.length < batchSize) {
2226
- batch.push(result.value);
2229
+ // process inline as we pull from the iterator — no intermediate array.
2230
+ // deleting from the map during iteration (via unregisterNode) is safe:
2231
+ // unvisited deleted entries are skipped, newly added nodes get visited.
2232
+ while (!result.done && processed < batchSize) {
2233
+ const node = result.value[1];
2234
+ if (node) {
2235
+ processBatchCallback(node);
2236
+ }
2237
+ processed++;
2227
2238
  result = iterator.next();
2228
2239
  }
2229
- if (batch.length > 0) {
2230
- batch.forEach(([_, node]) => {
2231
- if (node) {
2232
- processBatchCallback(node);
2233
- }
2234
- });
2235
- setTimeout(processNextBatch, 50);
2240
+ if (processed > 0) {
2241
+ // yield the thread between batches so the browser can run other work
2242
+ onScheduled(setTimeout(processNextBatch, 50));
2243
+ }
2244
+ else {
2245
+ onComplete();
2236
2246
  }
2237
2247
  }
2238
2248
  processNextBatch();
@@ -2271,17 +2281,29 @@ class Maintainer {
2271
2281
  constructor(nodes, unregisterNode, options) {
2272
2282
  this.nodes = nodes;
2273
2283
  this.unregisterNode = unregisterNode;
2284
+ this.isScanning = false;
2274
2285
  this.start = () => {
2275
2286
  if (!this.options.enabled) {
2276
2287
  return;
2277
2288
  }
2278
2289
  this.stop();
2279
2290
  this.interval = setInterval(() => {
2291
+ // a previous scan may still be walking the map across batch timeouts
2292
+ // (large DOM and/or background-tab timer throttling). don't pile up.
2293
+ if (this.isScanning) {
2294
+ return;
2295
+ }
2296
+ this.isScanning = true;
2280
2297
  processMapInBatches(this.nodes, this.options.batchSize, (node) => {
2281
2298
  const isActive = isNodeStillActive(node)[0];
2282
2299
  if (!isActive) {
2283
2300
  this.unregisterNode(node);
2284
2301
  }
2302
+ }, (timeout) => {
2303
+ this.batchTimeout = timeout;
2304
+ }, () => {
2305
+ this.batchTimeout = undefined;
2306
+ this.isScanning = false;
2285
2307
  });
2286
2308
  }, this.options.interval);
2287
2309
  };
@@ -2289,6 +2311,11 @@ class Maintainer {
2289
2311
  if (this.interval) {
2290
2312
  clearInterval(this.interval);
2291
2313
  }
2314
+ if (this.batchTimeout) {
2315
+ clearTimeout(this.batchTimeout);
2316
+ this.batchTimeout = undefined;
2317
+ }
2318
+ this.isScanning = false;
2292
2319
  };
2293
2320
  this.options = { ...defaults$1, ...options };
2294
2321
  }
@@ -4249,7 +4276,7 @@ class App {
4249
4276
  this.stopCallbacks = [];
4250
4277
  this.commitCallbacks = [];
4251
4278
  this.activityState = ActivityState.NotActive;
4252
- this.version = '18.0.16'; // TODO: version compatability check inside each plugin.
4279
+ this.version = '18.0.17-beta.0'; // TODO: version compatability check inside each plugin.
4253
4280
  this.socketMode = false;
4254
4281
  this.compressionThreshold = 24 * 1000;
4255
4282
  this.bc = null;
@@ -9584,7 +9611,7 @@ class ConstantProperties {
9584
9611
  user_id: this.user_id,
9585
9612
  distinct_id: this.deviceId,
9586
9613
  sdk_edition: 'web',
9587
- sdk_version: '18.0.16',
9614
+ sdk_version: '18.0.17-beta.0',
9588
9615
  timezone: getUTCOffsetString(),
9589
9616
  search_engine: this.searchEngine,
9590
9617
  };
@@ -10286,7 +10313,7 @@ class API {
10286
10313
  this.signalStartIssue = (reason, missingApi) => {
10287
10314
  const doNotTrack = this.checkDoNotTrack();
10288
10315
  console.log("Tracker couldn't start due to:", JSON.stringify({
10289
- trackerVersion: '18.0.16',
10316
+ trackerVersion: '18.0.17-beta.0',
10290
10317
  projectKey: this.options.projectKey,
10291
10318
  doNotTrack,
10292
10319
  reason: missingApi.length ? `missing api: ${missingApi.join(',')}` : reason,