@datalyr/web 1.6.1 → 1.6.2

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.
@@ -1,5 +1,5 @@
1
1
  /**
2
- * @datalyr/web v1.6.1
2
+ * @datalyr/web v1.6.2
3
3
  * Datalyr Web SDK - Modern attribution tracking for web applications
4
4
  * (c) 2026 Datalyr Inc.
5
5
  * Released under the MIT License
@@ -247,15 +247,21 @@ class SafeStorage {
247
247
  this.prefix = 'dl_';
248
248
  // Test if storage is available
249
249
  try {
250
+ if (!storage)
251
+ throw new Error('no storage'); // server / SSR
250
252
  const testKey = 'dl_test__' + Math.random();
251
253
  storage.setItem(testKey, '1');
252
254
  storage.removeItem(testKey);
253
255
  this.storage = storage;
254
256
  }
255
257
  catch (_a) {
256
- // Storage not available (Safari private mode, etc.)
258
+ // Storage not available (server-side render, Safari private mode, etc.)
257
259
  this.storage = null;
258
- console.warn('[Datalyr] Storage not available, using memory fallback');
260
+ // Only warn in the browser on the server there's intentionally no
261
+ // storage and the SDK does no real work until init() runs client-side.
262
+ if (typeof window !== 'undefined') {
263
+ console.warn('[Datalyr] Storage not available, using memory fallback');
264
+ }
259
265
  }
260
266
  }
261
267
  get(key, defaultValue = null) {
@@ -564,9 +570,16 @@ class CookieStorage {
564
570
  return '';
565
571
  }
566
572
  }
567
- // Export singleton instances for storage
568
- const storage = new SafeStorage(window.localStorage);
569
- new SafeStorage(window.sessionStorage);
573
+ // Export singleton instances for storage.
574
+ // Guard the browser globals so importing the SDK on the server (SSR / Node)
575
+ // doesn't throw `window is not defined`. On the server these fall back to
576
+ // in-memory storage; real storage is wired when the module re-evaluates in the
577
+ // browser. (Without this, any static `import` of the SDK in a Next.js client
578
+ // component crashes server rendering.)
579
+ const browserLocalStorage = typeof window !== 'undefined' ? window.localStorage : undefined;
580
+ const browserSessionStorage = typeof window !== 'undefined' ? window.sessionStorage : undefined;
581
+ const storage = new SafeStorage(browserLocalStorage);
582
+ new SafeStorage(browserSessionStorage);
570
583
  // Default cookie instance for backwards compatibility
571
584
  const cookies = new CookieStorage();
572
585