@absolutejs/beacon 0.6.33 → 0.6.34

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/index.js CHANGED
@@ -760,7 +760,7 @@ var createBeacon = (options) => {
760
760
  const MAIN_THREAD_STALL_DEFAULT_WINDOW_MS = 1e4;
761
761
  const RELOAD_LOOP_COUNT = 4;
762
762
  const RELOAD_LOOP_WINDOW_MS = 60000;
763
- const RELOAD_LOOP_STORAGE_KEY = "beacon:reload-history-v2";
763
+ const RELOAD_LOOP_STORAGE_KEY = "beacon:reload-history-v3";
764
764
  const STALE_RELEASE_STORAGE_KEY = "beacon:release-first-seen";
765
765
  const STALE_RELEASE_GRACE_MS = 600000;
766
766
  const STALE_RELEASE_HISTORY_LIMIT = 5;
@@ -3731,14 +3731,37 @@ var createBeacon = (options) => {
3731
3731
  const route = shortUrl(location.href);
3732
3732
  const raw = sessionStorage.getItem(RELOAD_LOOP_STORAGE_KEY);
3733
3733
  const parsed = raw === null ? [] : JSON.parse(raw);
3734
- const history2 = (Array.isArray(parsed) ? parsed : []).filter((entry) => entry !== null && typeof entry === "object" && typeof entry.at === "number" && typeof entry.route === "string" && now - entry.at < RELOAD_LOOP_WINDOW_MS);
3734
+ let history2 = (Array.isArray(parsed) ? parsed : []).filter((entry) => entry !== null && typeof entry === "object" && typeof entry.at === "number" && typeof entry.route === "string" && now - entry.at < RELOAD_LOOP_WINDOW_MS);
3735
+ let entryKind = "app";
3736
+ if (document.referrer !== "") {
3737
+ const referrer = new URL(document.referrer, location.href);
3738
+ if (referrer.origin !== location.origin) {
3739
+ history2 = [];
3740
+ entryKind = "external";
3741
+ } else {
3742
+ const controllerScript = navigator.serviceWorker?.controller?.scriptURL;
3743
+ if (controllerScript !== undefined && new URL(controllerScript, location.href).pathname === referrer.pathname) {
3744
+ history2 = [];
3745
+ entryKind = "service-worker-update";
3746
+ }
3747
+ }
3748
+ }
3735
3749
  history2.push({ at: now, route });
3736
3750
  sessionStorage.setItem(RELOAD_LOOP_STORAGE_KEY, JSON.stringify(history2));
3737
- const routeLoads = history2.filter((entry) => entry.route === route);
3738
- if (routeLoads.length >= RELOAD_LOOP_COUNT) {
3751
+ let loadCount = 0;
3752
+ for (let index = history2.length - 1;index >= 0; index -= 1) {
3753
+ if (history2[index]?.route !== route)
3754
+ break;
3755
+ loadCount += 1;
3756
+ }
3757
+ if (loadCount === RELOAD_LOOP_COUNT) {
3758
+ const firstLoad = history2.at(-loadCount)?.at ?? now;
3739
3759
  emitSignal(`Reload loop — repeated page loads within a minute — ${shortUrl(location.href)}`, {
3740
- loadCount: String(routeLoads.length),
3741
- signal: BEACON_SIGNAL.RELOAD_LOOP
3760
+ entryKind,
3761
+ loadCount: String(loadCount),
3762
+ navigationType: navigation?.type ?? "unknown",
3763
+ signal: BEACON_SIGNAL.RELOAD_LOOP,
3764
+ windowMs: String(now - firstLoad)
3742
3765
  });
3743
3766
  }
3744
3767
  }
@@ -4052,5 +4075,5 @@ export {
4052
4075
  BEACON_ATTRIBUTE
4053
4076
  };
4054
4077
 
4055
- //# debugId=65E8387E26687EFE64756E2164756E21
4078
+ //# debugId=6A2881BC0E745B5164756E2164756E21
4056
4079
  //# sourceMappingURL=index.js.map