@sledge-app/react-instant-search 2.0.72 → 2.0.74

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.
@@ -720,6 +720,77 @@ const getSortMap = ({
720
720
  "title-descending": "title:desc"
721
721
  };
722
722
  };
723
+ let onStorageFallback;
724
+ const getWindowStore = () => {
725
+ if (typeof window === "undefined")
726
+ return null;
727
+ window.__SLEDGE_STORAGE__ = window.__SLEDGE_STORAGE__ || { data: {} };
728
+ return window.__SLEDGE_STORAGE__;
729
+ };
730
+ const getFallbackValue = (key) => {
731
+ var _a;
732
+ const store = getWindowStore();
733
+ return ((_a = store == null ? void 0 : store.data) == null ? void 0 : _a[key]) ?? null;
734
+ };
735
+ const setFallbackValue = (key, value) => {
736
+ const store = getWindowStore();
737
+ if (!store)
738
+ return;
739
+ store.data[key] = value;
740
+ };
741
+ const deleteFallbackValue = (key) => {
742
+ const store = getWindowStore();
743
+ if (!store)
744
+ return;
745
+ delete store.data[key];
746
+ };
747
+ const reportFallback = (key, error, operation) => {
748
+ var _a, _b;
749
+ try {
750
+ onStorageFallback == null ? void 0 : onStorageFallback(key, error, operation);
751
+ } catch {
752
+ }
753
+ if (typeof window !== "undefined") {
754
+ try {
755
+ (_b = (_a = window.posthog) == null ? void 0 : _a.capture) == null ? void 0 : _b.call(_a, "sledge_localstorage_fallback", {
756
+ key,
757
+ operation,
758
+ errorName: error == null ? void 0 : error.name
759
+ });
760
+ } catch {
761
+ }
762
+ }
763
+ };
764
+ const safeSetItem = (key, value) => {
765
+ if (typeof window === "undefined")
766
+ return;
767
+ if (typeof localStorage !== "undefined") {
768
+ try {
769
+ localStorage.setItem(key, value);
770
+ deleteFallbackValue(key);
771
+ return;
772
+ } catch (error) {
773
+ reportFallback(key, error, "setItem");
774
+ }
775
+ } else {
776
+ reportFallback(key, new Error("localStorage_unavailable"), "setItem");
777
+ }
778
+ setFallbackValue(key, value);
779
+ };
780
+ const safeGetItem = (key) => {
781
+ const fallbackValue = getFallbackValue(key);
782
+ if (fallbackValue !== null)
783
+ return fallbackValue;
784
+ if (typeof localStorage !== "undefined") {
785
+ try {
786
+ return localStorage.getItem(key);
787
+ } catch (error) {
788
+ reportFallback(key, error, "getItem");
789
+ return getFallbackValue(key);
790
+ }
791
+ }
792
+ return getFallbackValue(key);
793
+ };
723
794
  const root = "";
724
795
  const Loading = "";
725
796
  const ConfirmationPopup = "";
@@ -1692,7 +1763,7 @@ const addToCart = async (data) => {
1692
1763
  });
1693
1764
  };
1694
1765
  const getWishlist = async (query, token) => {
1695
- let sledgeAuthApp = token ? token : typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1766
+ let sledgeAuthApp = token ? token : safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
1696
1767
  let queryParams = "?" + new URLSearchParams({
1697
1768
  ...query || {}
1698
1769
  }).toString();
@@ -1709,7 +1780,7 @@ const getWishlist = async (query, token) => {
1709
1780
  };
1710
1781
  const addWishlist = async (data) => {
1711
1782
  const { productId, productVariantId, productName, productVendor, productSku, productVariantName, productLink, productImage, productCurrency, productPrice, type = "toggle" } = data;
1712
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1783
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
1713
1784
  let url = `${API_URL}/wishlist`;
1714
1785
  let payload = {
1715
1786
  product: JSON.stringify({
@@ -1738,7 +1809,7 @@ const addWishlist = async (data) => {
1738
1809
  });
1739
1810
  };
1740
1811
  const bulkAddWishlist = async (data) => {
1741
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1812
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
1742
1813
  let products = data.map((item) => {
1743
1814
  const { productId, productVariantId, productName, productVariantName, productLink, productImage, productCurrency, productPrice } = item;
1744
1815
  return {
@@ -1773,7 +1844,7 @@ const bulkAddWishlist = async (data) => {
1773
1844
  });
1774
1845
  };
1775
1846
  const getWishlistInfo = async ({ token = "", query = null }) => {
1776
- let sledgeAuthApp = token ? token : typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1847
+ let sledgeAuthApp = token ? token : safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
1777
1848
  let queryParams = "?" + new URLSearchParams({
1778
1849
  ...query
1779
1850
  }).toString();
@@ -1791,7 +1862,7 @@ const getWishlistInfo = async ({ token = "", query = null }) => {
1791
1862
  const checkWishlist = async ({ id, variantId = "", query = null }) => {
1792
1863
  let convertId = sanitizeDataId(id);
1793
1864
  let convertVariantId = variantId ? sanitizeDataId(variantId) : "";
1794
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1865
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
1795
1866
  let queryParams = "?" + new URLSearchParams({
1796
1867
  variant_id: convertVariantId,
1797
1868
  ...query
@@ -1808,7 +1879,7 @@ const checkWishlist = async ({ id, variantId = "", query = null }) => {
1808
1879
  });
1809
1880
  };
1810
1881
  const checkWishlists = async () => {
1811
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1882
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
1812
1883
  let url = `${API_URL}/wishlist/checks`;
1813
1884
  return await fetchApi({
1814
1885
  url,
@@ -1821,7 +1892,7 @@ const checkWishlists = async () => {
1821
1892
  });
1822
1893
  };
1823
1894
  const clearWishlist = async () => {
1824
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1895
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
1825
1896
  let url = `${API_URL}/wishlist/clear`;
1826
1897
  return await fetchApi({
1827
1898
  url,
@@ -1835,7 +1906,7 @@ const clearWishlist = async () => {
1835
1906
  };
1836
1907
  const addToCartTrigger$2 = async (data) => {
1837
1908
  const { productId } = data;
1838
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
1909
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
1839
1910
  let url = `${API_URL}/wishlist/cart`;
1840
1911
  let payload = {
1841
1912
  product: JSON.stringify({
@@ -1901,11 +1972,11 @@ const BadgeCounter = (props) => {
1901
1972
  setIsMaximizeTotalWishlist(valueTotalWishlist > 99);
1902
1973
  setIsFirstLoading(false);
1903
1974
  setIsLoading(false);
1904
- localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER, valueTotalWishlist);
1975
+ safeSetItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER, String(valueTotalWishlist));
1905
1976
  }
1906
1977
  });
1907
1978
  } else {
1908
- localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER, totalWishlist);
1979
+ safeSetItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER, String(totalWishlist));
1909
1980
  }
1910
1981
  };
1911
1982
  const handleSettings = async (LOCAL_STORAGE_WISHLIST_SETTING) => {
@@ -1920,7 +1991,7 @@ const BadgeCounter = (props) => {
1920
1991
  React__default.useEffect(() => {
1921
1992
  if (!isRenderAppWishlist)
1922
1993
  return;
1923
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
1994
+ handleSettings(safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
1924
1995
  }, [isRenderAppWishlist]);
1925
1996
  React__default.useEffect(() => {
1926
1997
  if (!(dataSettings == null ? void 0 : dataSettings.launch_point) || !isRenderAppWishlist)
@@ -1934,7 +2005,7 @@ const BadgeCounter = (props) => {
1934
2005
  triggerRenderWishlistBadge(false);
1935
2006
  handleGetWishlistInfo();
1936
2007
  }, [valueRenderWishlistBadge, isRenderAppWishlist]);
1937
- const defaultTotalWishlist = isJsVersion ? (localStorage == null ? void 0 : localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER)) || null : null;
2008
+ const defaultTotalWishlist = isJsVersion ? safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER) || null : null;
1938
2009
  const contentTotalWishlist = isFirstLoading ? defaultTotalWishlist : isLoading || isRequiredLogin ? 0 : `${isMaximizeTotalWishlist ? "99+" : totalWishlist}` || 0;
1939
2010
  return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { "data-wishlist-counter": contentTotalWishlist, children: contentTotalWishlist });
1940
2011
  };
@@ -2645,7 +2716,7 @@ const WidgetRoot = (props) => {
2645
2716
  }
2646
2717
  };
2647
2718
  const handleSetWishlistData = async (isLoadMore = false, init = false) => {
2648
- var _a2, _b2, _c2;
2719
+ var _a2, _b2;
2649
2720
  const searchParams = new URLSearchParams(document.location.search);
2650
2721
  const getShareId = (params == null ? void 0 : params.shareId) ? params.shareId : (searchParams == null ? void 0 : searchParams.get(queryShareId)) || "";
2651
2722
  setIsLoading(isRefreshWidgetList ? true : !isLoadMore);
@@ -2672,15 +2743,16 @@ const WidgetRoot = (props) => {
2672
2743
  response = propsData;
2673
2744
  } else
2674
2745
  response = await getWishlist(queryParam);
2746
+ const responseData = (response == null ? void 0 : response.data) ?? [];
2675
2747
  run = ((_a2 = response == null ? void 0 : response.status) == null ? void 0 : _a2.code) === 200 || false;
2676
- valueWishlistData = !((_b2 = response.data) == null ? void 0 : _b2.length) ? [] : (prevState) => (wishlistData == null ? void 0 : wishlistData.length) && isLoadMore ? [...prevState, ...response.data] : response.data;
2677
- valueTotalPage = ((_c2 = response == null ? void 0 : response.page) == null ? void 0 : _c2.total_page) || 1;
2748
+ valueWishlistData = !responseData.length ? [] : (prevState) => (wishlistData == null ? void 0 : wishlistData.length) && isLoadMore ? [...prevState, ...responseData] : responseData;
2749
+ valueTotalPage = ((_b2 = response == null ? void 0 : response.page) == null ? void 0 : _b2.total_page) || 1;
2678
2750
  if (run) {
2679
2751
  setWishlistData(valueWishlistData);
2680
2752
  setTotalPage(valueTotalPage);
2681
- setIsLoading(false);
2682
- setIsRefreshWidgetList(false);
2683
2753
  }
2754
+ setIsLoading(false);
2755
+ setIsRefreshWidgetList(false);
2684
2756
  };
2685
2757
  const handleShareData = async () => {
2686
2758
  var _a2, _b2, _c2, _d;
@@ -2721,8 +2793,8 @@ const WidgetRoot = (props) => {
2721
2793
  let responseGeneral;
2722
2794
  let responseInstantSearch;
2723
2795
  response = wishlistPreviewSettings || JSON.parse(LOCAL_STORAGE_WISHLIST_SETTING);
2724
- responseGeneral = generalPreviewSettings || JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
2725
- responseInstantSearch = instantSearchPreviewSettings || JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
2796
+ responseGeneral = generalPreviewSettings || JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
2797
+ responseInstantSearch = instantSearchPreviewSettings || JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
2726
2798
  if (!response)
2727
2799
  return;
2728
2800
  const { sorts } = response == null ? void 0 : response.display;
@@ -2734,7 +2806,7 @@ const WidgetRoot = (props) => {
2734
2806
  setInstantSearchSettings(responseInstantSearch);
2735
2807
  };
2736
2808
  useEffectOnChange(() => {
2737
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
2809
+ handleSettings(safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
2738
2810
  }, [previewSettings]);
2739
2811
  React__default.useEffect(() => {
2740
2812
  if (!isRenderAppWishlist)
@@ -2776,7 +2848,7 @@ const WidgetRoot = (props) => {
2776
2848
  };
2777
2849
  }
2778
2850
  handleShareData();
2779
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
2851
+ handleSettings(safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
2780
2852
  setIsFirstLoading(false);
2781
2853
  }, [isRenderAppWishlist]);
2782
2854
  React__default.useEffect(() => {
@@ -2901,7 +2973,7 @@ const Badge = (props) => {
2901
2973
  setIsMaximizeTotalWishlist(valueTotalWishlist > 99);
2902
2974
  setProxyUrl(valueProxyUrl);
2903
2975
  setData(valueData);
2904
- localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER, valueTotalWishlist);
2976
+ safeSetItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER, String(valueTotalWishlist));
2905
2977
  },
2906
2978
  wishlistPreviewSettings,
2907
2979
  generalPreviewSettings
@@ -2948,7 +3020,7 @@ const Badge = (props) => {
2948
3020
  }
2949
3021
  };
2950
3022
  useEffectOnChange(() => {
2951
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
3023
+ handleSettings(safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
2952
3024
  handleConfirmationPopup({
2953
3025
  isPreviewSettings: true
2954
3026
  });
@@ -2956,7 +3028,7 @@ const Badge = (props) => {
2956
3028
  React__default.useEffect(() => {
2957
3029
  if (!isRenderAppWishlist)
2958
3030
  return;
2959
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
3031
+ handleSettings(safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
2960
3032
  }, [isRenderAppWishlist]);
2961
3033
  React__default.useEffect(() => {
2962
3034
  if (!(dataSettings == null ? void 0 : dataSettings.launch_point) || !isRenderAppWishlist)
@@ -3016,7 +3088,7 @@ const Badge = (props) => {
3016
3088
  data: isJsVersion ? {
3017
3089
  ...data,
3018
3090
  ...{
3019
- total_data: (localStorage == null ? void 0 : localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER)) || (data == null ? void 0 : data.total_data)
3091
+ total_data: safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER) || (data == null ? void 0 : data.total_data)
3020
3092
  }
3021
3093
  } : data
3022
3094
  }
@@ -3043,7 +3115,7 @@ const Badge = (props) => {
3043
3115
  data: isJsVersion ? {
3044
3116
  ...data,
3045
3117
  ...{
3046
- total_data: (localStorage == null ? void 0 : localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER)) || (data == null ? void 0 : data.total_data)
3118
+ total_data: safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER) || (data == null ? void 0 : data.total_data)
3047
3119
  }
3048
3120
  } : data
3049
3121
  }
@@ -3067,7 +3139,7 @@ const Badge = (props) => {
3067
3139
  data: isJsVersion ? {
3068
3140
  ...data,
3069
3141
  ...{
3070
- total_data: (localStorage == null ? void 0 : localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER)) || (data == null ? void 0 : data.total_data)
3142
+ total_data: safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER) || (data == null ? void 0 : data.total_data)
3071
3143
  }
3072
3144
  } : data
3073
3145
  }
@@ -3093,7 +3165,7 @@ const Badge = (props) => {
3093
3165
  data: isJsVersion ? {
3094
3166
  ...data,
3095
3167
  ...{
3096
- total_data: (localStorage == null ? void 0 : localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER)) || (data == null ? void 0 : data.total_data)
3168
+ total_data: safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_BADGE_COUNTER) || (data == null ? void 0 : data.total_data)
3097
3169
  }
3098
3170
  } : data
3099
3171
  }
@@ -3113,7 +3185,8 @@ const Badge = (props) => {
3113
3185
  setOpen: setOpenFlyoutWishlistWidget,
3114
3186
  position: "right",
3115
3187
  className: "sledge-flyout-widget__wishlist",
3116
- withBlurEffect: true
3188
+ withBlurEffect: true,
3189
+ unmountContentOnLoading: false
3117
3190
  }
3118
3191
  ) : null,
3119
3192
  isFirstLoading ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: position === "none" ? /* @__PURE__ */ jsxRuntimeExports.jsx(HeaderMenu, {}) : String(position).includes("bottom") ? /* @__PURE__ */ jsxRuntimeExports.jsx(FloatingIcon, {}) : /* @__PURE__ */ jsxRuntimeExports.jsx(FloatingFull, {}) })
@@ -3147,7 +3220,7 @@ const BadgeCounterInitSelector = (props) => {
3147
3220
  productReview: true,
3148
3221
  instantSearch: true
3149
3222
  },
3150
- sledgeAnonymId: localStorage.getItem(LOCAL_STORAGE_KEY.ANONYM_ID) || "",
3223
+ sledgeAnonymId: safeGetItem(LOCAL_STORAGE_KEY.ANONYM_ID) || "",
3151
3224
  isJsVersion: true
3152
3225
  },
3153
3226
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(BadgeCounter, { previewSettings })
@@ -3161,7 +3234,7 @@ const BadgeInitSelector = (props) => {
3161
3234
  var _a;
3162
3235
  const { selector = "", reload = false, previewSettings = null } = props || {};
3163
3236
  const getSelector = selector || SELECTOR.WISHLIST.ELEMENT_BADGE;
3164
- const LOCAL_STORAGE_WISHLIST_SETTING = localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) ? JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null) : null;
3237
+ const LOCAL_STORAGE_WISHLIST_SETTING = safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) ? JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null) : null;
3165
3238
  const sledgeWishlistSettings = objectPresent((_a = previewSettings == null ? void 0 : previewSettings.settings) == null ? void 0 : _a.wishlist) || LOCAL_STORAGE_WISHLIST_SETTING;
3166
3239
  let element = Array.from(document.querySelectorAll(getSelector));
3167
3240
  let isElementDetected = !element || element && !element.length;
@@ -3202,7 +3275,7 @@ const BadgeInitSelector = (props) => {
3202
3275
  productReview: true,
3203
3276
  instantSearch: true
3204
3277
  },
3205
- sledgeAnonymId: localStorage.getItem(LOCAL_STORAGE_KEY.ANONYM_ID) || "",
3278
+ sledgeAnonymId: safeGetItem(LOCAL_STORAGE_KEY.ANONYM_ID) || "",
3206
3279
  isJsVersion: true
3207
3280
  },
3208
3281
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -3253,7 +3326,7 @@ const BadgeInitSelector = (props) => {
3253
3326
  productReview: true,
3254
3327
  instantSearch: true
3255
3328
  },
3256
- sledgeAnonymId: localStorage.getItem(LOCAL_STORAGE_KEY.ANONYM_ID) || "",
3329
+ sledgeAnonymId: safeGetItem(LOCAL_STORAGE_KEY.ANONYM_ID) || "",
3257
3330
  isJsVersion: true
3258
3331
  },
3259
3332
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -3305,7 +3378,7 @@ const BadgeInitSelector = (props) => {
3305
3378
  productReview: true,
3306
3379
  instantSearch: true
3307
3380
  },
3308
- sledgeAnonymId: localStorage.getItem(LOCAL_STORAGE_KEY.ANONYM_ID) || "",
3381
+ sledgeAnonymId: safeGetItem(LOCAL_STORAGE_KEY.ANONYM_ID) || "",
3309
3382
  isJsVersion: true
3310
3383
  },
3311
3384
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -3529,7 +3602,7 @@ const Trigger = (props) => {
3529
3602
  setIsRequiredLogin(sledgeAnonymId && is_required_login2);
3530
3603
  };
3531
3604
  useEffectOnChange(() => {
3532
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
3605
+ handleSettings(safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
3533
3606
  handleConfirmationPopup({
3534
3607
  isPreviewSettings: true
3535
3608
  });
@@ -3546,7 +3619,7 @@ const Trigger = (props) => {
3546
3619
  handleCheckWishlist();
3547
3620
  };
3548
3621
  }
3549
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
3622
+ handleSettings(safeGetItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
3550
3623
  }, [isRenderAppWishlist, hasEntry]);
3551
3624
  useEffectOnChange(() => {
3552
3625
  setIsRequiredLogin(sledgeAnonymId && is_required_login);
@@ -3634,7 +3707,7 @@ const ElementInit = (item, reload, previewSettings) => {
3634
3707
  productReview: true,
3635
3708
  instantSearch: true
3636
3709
  },
3637
- sledgeAnonymId: localStorage.getItem(LOCAL_STORAGE_KEY.ANONYM_ID) || "",
3710
+ sledgeAnonymId: safeGetItem(LOCAL_STORAGE_KEY.ANONYM_ID) || "",
3638
3711
  isJsVersion: true
3639
3712
  },
3640
3713
  children: /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -3680,7 +3753,7 @@ const TriggerInitSelector = (props) => {
3680
3753
  const getReviewInfo = async (props) => {
3681
3754
  const { productId = null, query = null } = props || {};
3682
3755
  let convertId = productId ? sanitizeDataId(productId) : "";
3683
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
3756
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
3684
3757
  let queryParams = "?" + new URLSearchParams({
3685
3758
  [PAYLOAD_API_ALIASES.Authorization]: sledgeAuthApp,
3686
3759
  ...query
@@ -3699,7 +3772,7 @@ const getReviewInfo = async (props) => {
3699
3772
  };
3700
3773
  const getProductsReviewInfo = async (ids, token) => {
3701
3774
  let convertIds = ids.map((v) => sanitizeDataId(v));
3702
- let sledgeAuthApp = token ? token : typeof localStorage !== "undefined" ? (localStorage == null ? void 0 : localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP)) || "" : "";
3775
+ let sledgeAuthApp = token ? token : safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
3703
3776
  let url = `${API_URL}/review/info/ids/${convertIds.join(",")}?${PAYLOAD_API_ALIASES.Authorization}=${sledgeAuthApp}`;
3704
3777
  return await fetchApi({
3705
3778
  url,
@@ -3836,7 +3909,7 @@ const Rating = (props) => {
3836
3909
  };
3837
3910
  useEffectOnChange(() => {
3838
3911
  handleSettings({
3839
- LOCAL_STORAGE_PRODUCT_REVIEW_SETTING: localStorage.getItem(LOCAL_STORAGE_KEY.PRODUCT_REVIEW_SETTING) || null,
3912
+ LOCAL_STORAGE_PRODUCT_REVIEW_SETTING: safeGetItem(LOCAL_STORAGE_KEY.PRODUCT_REVIEW_SETTING) || null,
3840
3913
  isPreviewSettings: true
3841
3914
  });
3842
3915
  }, [previewSettings]);
@@ -3867,7 +3940,7 @@ const Rating = (props) => {
3867
3940
  if (isProductIdChanged)
3868
3941
  setIsFirstLoading(true);
3869
3942
  handleSettings({
3870
- LOCAL_STORAGE_PRODUCT_REVIEW_SETTING: localStorage.getItem(LOCAL_STORAGE_KEY.PRODUCT_REVIEW_SETTING) || null
3943
+ LOCAL_STORAGE_PRODUCT_REVIEW_SETTING: safeGetItem(LOCAL_STORAGE_KEY.PRODUCT_REVIEW_SETTING) || null
3871
3944
  });
3872
3945
  }, [isRenderAppProductReview, hasEntry, productId]);
3873
3946
  React__default.useEffect(() => {
@@ -4235,7 +4308,7 @@ WidgetHeader.Sort = WidgetHeaderSort;
4235
4308
  WidgetHeader.AddTrigger = WidgetHeaderAddTrigger;
4236
4309
  WidgetHeader.Summary = WidgetHeaderSummary;
4237
4310
  const search = async (index, payload) => {
4238
- let sledgeInstantSearchAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_AUTH_APP) || "" : "";
4311
+ let sledgeInstantSearchAuthApp = safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_AUTH_APP) || "";
4239
4312
  let url = `${INSTANT_SEARCH_ENGINE_URL}/indexes/${index}/search`;
4240
4313
  let headers = {
4241
4314
  "Content-Type": "application/json"
@@ -4252,7 +4325,7 @@ const search = async (index, payload) => {
4252
4325
  });
4253
4326
  };
4254
4327
  const multiSearch = async (payload, token) => {
4255
- let sledgeInstantSearchAuthApp = token ? token : typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_AUTH_APP) || "" : "";
4328
+ let sledgeInstantSearchAuthApp = token ? token : safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_AUTH_APP) || "";
4256
4329
  let url = `${INSTANT_SEARCH_ENGINE_URL}/multi-search`;
4257
4330
  let headers = {
4258
4331
  "Content-Type": "application/json"
@@ -4270,7 +4343,7 @@ const multiSearch = async (payload, token) => {
4270
4343
  };
4271
4344
  const searchTrigger = async (data) => {
4272
4345
  const { keyword, resultCount } = data;
4273
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
4346
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
4274
4347
  let url = `${API_URL}/instantsearch/statistics/search`;
4275
4348
  let headers = {
4276
4349
  "Content-Type": "application/json"
@@ -4294,7 +4367,7 @@ const searchTrigger = async (data) => {
4294
4367
  };
4295
4368
  const productClickTrigger$1 = async (data) => {
4296
4369
  const { productId } = data;
4297
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
4370
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
4298
4371
  let url = `${API_URL}/instantsearch/statistics/click`;
4299
4372
  let headers = {
4300
4373
  "Content-Type": "application/json"
@@ -4319,7 +4392,7 @@ const productClickTrigger$1 = async (data) => {
4319
4392
  };
4320
4393
  const addToCartTrigger$1 = async (data) => {
4321
4394
  const { productId } = data;
4322
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
4395
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
4323
4396
  let url = `${API_URL}/instantsearch/statistics/cart`;
4324
4397
  let headers = {
4325
4398
  "Content-Type": "application/json"
@@ -4345,7 +4418,7 @@ const addToCartTrigger$1 = async (data) => {
4345
4418
  const productRecommendationSourceApps = ["recently-viewed", "related-product", "hand-picked", "new-arrival", "personalized-curated"];
4346
4419
  const productClickTrigger = async (data) => {
4347
4420
  const { productId, sourceApp } = data;
4348
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
4421
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
4349
4422
  let url = `${API_URL}/product-recommendation/statistics/click`;
4350
4423
  let headers = {
4351
4424
  "Content-Type": "application/json"
@@ -4369,7 +4442,7 @@ const productClickTrigger = async (data) => {
4369
4442
  };
4370
4443
  const addToCartTrigger = async (data) => {
4371
4444
  const { productId, sourceApp } = data;
4372
- let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
4445
+ let sledgeAuthApp = safeGetItem(LOCAL_STORAGE_KEY.AUTH_APP) || "";
4373
4446
  let url = `${API_URL}/product-recommendation/statistics/cart`;
4374
4447
  let headers = {
4375
4448
  "Content-Type": "application/json"
@@ -4594,7 +4667,7 @@ const VariantSelector = (props) => {
4594
4667
  const defaultOptionClass = `
4595
4668
  ${selectedOption === item ? "sledge__product-variant-size-swatch-active" : ""} sledge__product-variant-size-swatch`;
4596
4669
  const colorOptionClass = `${selectedOption === item ? "sledge__product-variant-color-swatch-active" : ""} sledge__product-variant-color-swatch`;
4597
- const colorDataSettings = ((_a3 = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING))) == null ? void 0 : _a3.colors) || [];
4670
+ const colorDataSettings = ((_a3 = JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING))) == null ? void 0 : _a3.colors) || [];
4598
4671
  const getColorSwatch = (colorDataSettings == null ? void 0 : colorDataSettings.filter(({ name }) => name === item)[0]) || {};
4599
4672
  const colorSwatch = (getColorSwatch == null ? void 0 : getColorSwatch.image) ? `url('${getColorSwatch == null ? void 0 : getColorSwatch.image}')` : (getColorSwatch == null ? void 0 : getColorSwatch.rgb) || item;
4600
4673
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -5197,7 +5270,7 @@ const ProductGrid = React__default.memo((props) => {
5197
5270
  };
5198
5271
  const handleSettings = () => {
5199
5272
  let responseGeneral;
5200
- responseGeneral = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
5273
+ responseGeneral = JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
5201
5274
  if (responseGeneral)
5202
5275
  setGeneralDataSettings(responseGeneral);
5203
5276
  };
@@ -5416,7 +5489,7 @@ const SkeletonItem = ({ width, height, rounded, color, style = {}, className = "
5416
5489
  setDataSettings(response);
5417
5490
  };
5418
5491
  React__default.useEffect(() => {
5419
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
5492
+ handleSettings(safeGetItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
5420
5493
  }, []);
5421
5494
  return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: ((_a = dataSettings == null ? void 0 : dataSettings.skeleton) == null ? void 0 : _a.enable) ? /* @__PURE__ */ jsxRuntimeExports.jsx(
5422
5495
  "div",
@@ -5449,7 +5522,7 @@ const SkeletonProductGrid = ({ count, type, isFlyout = false, currentColumnGrid
5449
5522
  setDataSettings(response);
5450
5523
  };
5451
5524
  React__default.useEffect(() => {
5452
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
5525
+ handleSettings(safeGetItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
5453
5526
  }, []);
5454
5527
  let components = [];
5455
5528
  for (let i = 0; i < count; i++) {
@@ -5795,7 +5868,18 @@ const DotButton = (props) => {
5795
5868
  return /* @__PURE__ */ jsxRuntimeExports.jsx("button", { type: "button", ...restProps, children });
5796
5869
  };
5797
5870
  const FlyoutSidebar$1 = "";
5798
- const FlyoutSidebar = ({ title, content, footer = null, open, setOpen, position = "left", className = "", withBlurEffect = false, flyoutInfoContent = null }) => {
5871
+ const FlyoutSidebar = ({
5872
+ title,
5873
+ content,
5874
+ footer = null,
5875
+ open,
5876
+ setOpen,
5877
+ position = "left",
5878
+ className = "",
5879
+ withBlurEffect = false,
5880
+ flyoutInfoContent = null,
5881
+ unmountContentOnLoading = true
5882
+ }) => {
5799
5883
  const [isLoading, setIsLoading] = React__default.useState(false);
5800
5884
  const [isScrollAtBottom, setIsScrollAtBottom] = React__default.useState(false);
5801
5885
  const contentContainerRef = React__default.useRef(null);
@@ -5844,11 +5928,11 @@ const FlyoutSidebar = ({ title, content, footer = null, open, setOpen, position
5844
5928
  {
5845
5929
  ref: contentContainerRef,
5846
5930
  className: `sledge__flyout-mobile-content ${showBlurEffect ? "sledge__flyout-mobile-content-blur-effect" : ""}`,
5847
- style: isLoading ? { display: "none" } : void 0,
5848
- children: content
5931
+ style: unmountContentOnLoading && isLoading ? { display: "none" } : void 0,
5932
+ children: unmountContentOnLoading && isLoading ? null : content
5849
5933
  }
5850
5934
  ),
5851
- footer ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__flyout-mobile-footer", style: isLoading ? { display: "none" } : void 0, children: footer }) : null
5935
+ footer ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__flyout-mobile-footer", style: unmountContentOnLoading && isLoading ? { display: "none" } : void 0, children: unmountContentOnLoading && isLoading ? null : footer }) : null
5852
5936
  ] })
5853
5937
  ] }),
5854
5938
  document.body
@@ -6291,7 +6375,7 @@ const SearchIconWidgetPopup = () => {
6291
6375
  };
6292
6376
  }
6293
6377
  handleSettings({
6294
- LOCAL_STORAGE_INSTANT_SEARCH_SETTING: localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null
6378
+ LOCAL_STORAGE_INSTANT_SEARCH_SETTING: safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null
6295
6379
  });
6296
6380
  }, [isRenderAppInstantSearch]);
6297
6381
  React__default.useEffect(() => {
@@ -6299,7 +6383,7 @@ const SearchIconWidgetPopup = () => {
6299
6383
  }, [showInfo]);
6300
6384
  React__default.useEffect(() => {
6301
6385
  if (Boolean(previousState && (previousState == null ? void 0 : previousState.keyword) !== keyword)) {
6302
- const INSTANT_SEARCH_SETTING = (handleFunctions == null ? void 0 : handleFunctions.instantSearchPreviewSettings) || JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
6386
+ const INSTANT_SEARCH_SETTING = (handleFunctions == null ? void 0 : handleFunctions.instantSearchPreviewSettings) || JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
6303
6387
  const delayDebounceFn = setTimeout(() => {
6304
6388
  if (INSTANT_SEARCH_SETTING)
6305
6389
  handleMultiSearch({
@@ -6312,7 +6396,7 @@ const SearchIconWidgetPopup = () => {
6312
6396
  }, [keyword]);
6313
6397
  useEffectOnChange(() => {
6314
6398
  handleSettings({
6315
- LOCAL_STORAGE_INSTANT_SEARCH_SETTING: localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null,
6399
+ LOCAL_STORAGE_INSTANT_SEARCH_SETTING: safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null,
6316
6400
  isPreviewSettings: true
6317
6401
  });
6318
6402
  }, [handleFunctions == null ? void 0 : handleFunctions.instantSearchPreviewSettings]);
@@ -8506,15 +8590,15 @@ const ColumnGridSelector = ({
8506
8590
  isDesktopLayout,
8507
8591
  showText = true
8508
8592
  }) => {
8509
- const desktopColumns = localStorage.getItem(LOCAL_STORAGE_KEY.GRID_DESKTOP_COLUMN) || "column-3";
8510
- const mobileColumns = localStorage.getItem(LOCAL_STORAGE_KEY.GRID_MOBILE_COLUMN) || "column-2";
8593
+ const desktopColumns = safeGetItem(LOCAL_STORAGE_KEY.GRID_DESKTOP_COLUMN) || "column-3";
8594
+ const mobileColumns = safeGetItem(LOCAL_STORAGE_KEY.GRID_MOBILE_COLUMN) || "column-2";
8511
8595
  const changeGridLayout = (type, value) => {
8512
8596
  const newLayout = { ...currentColumnGrid, [type]: value };
8513
8597
  setCurrentColumnGrid == null ? void 0 : setCurrentColumnGrid(newLayout);
8514
8598
  if (type === "desktop") {
8515
- localStorage.setItem(LOCAL_STORAGE_KEY.GRID_DESKTOP_COLUMN, value);
8599
+ safeSetItem(LOCAL_STORAGE_KEY.GRID_DESKTOP_COLUMN, value);
8516
8600
  } else {
8517
- localStorage.setItem(LOCAL_STORAGE_KEY.GRID_MOBILE_COLUMN, value);
8601
+ safeSetItem(LOCAL_STORAGE_KEY.GRID_MOBILE_COLUMN, value);
8518
8602
  }
8519
8603
  };
8520
8604
  React__default.useEffect(() => {
@@ -9416,15 +9500,15 @@ const SearchResultWidget = (props) => {
9416
9500
  const querySortBy = (query == null ? void 0 : query.sortBy) ? query.sortBy : DEFAULT_QUERY_PARAM.SORT_BY;
9417
9501
  const queryPage = (query == null ? void 0 : query.page) ? query.page : DEFAULT_QUERY_PARAM.PAGE;
9418
9502
  const queryLimit = (query == null ? void 0 : query.limit) ? query.limit : DEFAULT_QUERY_PARAM.LIMIT;
9419
- const desktopColumns = localStorage.getItem(LOCAL_STORAGE_KEY.GRID_DESKTOP_COLUMN) || "column-3";
9420
- const mobileColumns = localStorage.getItem(LOCAL_STORAGE_KEY.GRID_MOBILE_COLUMN) || "column-2";
9503
+ const desktopColumns = safeGetItem(LOCAL_STORAGE_KEY.GRID_DESKTOP_COLUMN) || "column-3";
9504
+ const mobileColumns = safeGetItem(LOCAL_STORAGE_KEY.GRID_MOBILE_COLUMN) || "column-2";
9421
9505
  const { collectionId } = params || {};
9422
9506
  const searchParams = typeof document !== "undefined" ? new URLSearchParams((_a = document == null ? void 0 : document.location) == null ? void 0 : _a.search) : null;
9423
9507
  const { generalPreviewSettings, instantSearchPreviewSettings, previewSettings } = usePreviewSettings({
9424
9508
  defaultSettings: previewSettingsProp,
9425
9509
  nestedProperty: layoutType === "product-filter" ? "sledge.instantSearch.productFilter.preview" : "sledge.instantSearch.searchResult.preview"
9426
9510
  });
9427
- const [settings] = React__default.useState(instantSearchPreviewSettings || typeof localStorage !== "undefined" ? JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || "{}") : {});
9511
+ const [settings] = React__default.useState(instantSearchPreviewSettings || JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || "{}"));
9428
9512
  const [isFirstLoading, setIsFirstLoading] = React__default.useState(!propsData);
9429
9513
  const [isLoading, setIsLoading] = React__default.useState(!propsData);
9430
9514
  const [keyword, setKeyword] = React__default.useState(searchParams == null ? void 0 : searchParams.get(queryKeyword));
@@ -9630,22 +9714,20 @@ const SearchResultWidget = (props) => {
9630
9714
  valueHierarchicalFacetAliases
9631
9715
  };
9632
9716
  };
9633
- const handleSetInitStates = ({ results = {}, data = {}, callback, isUpdateFilter = false }) => {
9717
+ const handleSetInitStates = ({ results = {}, data, callback, isUpdateFilter = false }) => {
9634
9718
  var _a2, _b2, _c2;
9635
- const { filters, index_product, tabs: tabs2, hidden_tags, show_out_of_stock, display, use_published_filter } = data;
9719
+ const { filters, index_product, tabs: tabs2, hidden_tags, show_out_of_stock, display, use_published_filter } = data ?? {};
9636
9720
  const {
9637
9721
  facetStats,
9638
9722
  totalHits: totalHitsResult,
9639
9723
  facetDistribution
9640
9724
  } = isUpdateFilter ? results || {} : layoutType === "default" ? ((_a2 = results == null ? void 0 : results.find) == null ? void 0 : _a2.call(results, ({ indexUid }) => indexUid.includes(index_product))) || {} : results || {};
9641
9725
  let totalHits = totalHitsResult || 0;
9642
- if (typeof localStorage !== "undefined") {
9643
- const INIT_TOTAL_HITS = Number(localStorage.getItem(layoutType === "default" ? LOCAL_STORAGE_KEY.SEARCH_RESULT_INIT_TOTAL_HITS : LOCAL_STORAGE_KEY.PRODUCT_FILTER_INIT_TOTAL_HITS) || 0);
9644
- if (!(INIT_TOTAL_HITS > 1)) {
9645
- localStorage.setItem(layoutType === "default" ? LOCAL_STORAGE_KEY.SEARCH_RESULT_INIT_TOTAL_HITS : LOCAL_STORAGE_KEY.PRODUCT_FILTER_INIT_TOTAL_HITS, totalHits);
9646
- }
9647
- totalHits = totalHits <= 1 ? INIT_TOTAL_HITS : totalHits;
9726
+ const INIT_TOTAL_HITS = Number(safeGetItem(layoutType === "default" ? LOCAL_STORAGE_KEY.SEARCH_RESULT_INIT_TOTAL_HITS : LOCAL_STORAGE_KEY.PRODUCT_FILTER_INIT_TOTAL_HITS) || 0);
9727
+ if (!(INIT_TOTAL_HITS > 1)) {
9728
+ safeSetItem(layoutType === "default" ? LOCAL_STORAGE_KEY.SEARCH_RESULT_INIT_TOTAL_HITS : LOCAL_STORAGE_KEY.PRODUCT_FILTER_INIT_TOTAL_HITS, String(totalHits));
9648
9729
  }
9730
+ totalHits = totalHits <= 1 ? INIT_TOTAL_HITS : totalHits;
9649
9731
  setTotalHitsProduct(totalHits || 0);
9650
9732
  let valueHideFilterWhenOneValue = ((_b2 = display == null ? void 0 : display.filter) == null ? void 0 : _b2.hide_when_one_value) && totalHits <= 1;
9651
9733
  let valueSearchResultFacets = facetDistribution ? Object.fromEntries(
@@ -9709,15 +9791,16 @@ const SearchResultWidget = (props) => {
9709
9791
  });
9710
9792
  };
9711
9793
  const handleInitStates = async (data) => {
9712
- const { filters, index_product, tabs: tabs2, hidden_tags, show_out_of_stock, display, use_published_filter } = data;
9713
- let getTabs = layoutType === "product-filter" ? tabs2.filter(({ index }) => index == null ? void 0 : index.includes(index_product)) : tabs2;
9714
- getTabs.map((tab) => {
9715
- var _a2, _b2, _c2, _d2, _e2, _f2;
9794
+ var _a2, _b2;
9795
+ const { filters, index_product, tabs: tabs2, hidden_tags, show_out_of_stock, display, use_published_filter } = data ?? {};
9796
+ const getTabs = layoutType === "product-filter" ? (_a2 = tabs2 == null ? void 0 : tabs2.filter) == null ? void 0 : _a2.call(tabs2, ({ index }) => index == null ? void 0 : index.includes(index_product)) : tabs2;
9797
+ (_b2 = getTabs == null ? void 0 : getTabs.map) == null ? void 0 : _b2.call(getTabs, (tab) => {
9798
+ var _a3, _b3, _c2, _d2, _e2, _f2;
9716
9799
  const { index } = tab;
9717
9800
  let isSetFilter2 = false;
9718
9801
  let getFacets = [];
9719
9802
  if (!isSetFilter2) {
9720
- let allowedFiltersCollectionId = (_c2 = (_b2 = (_a2 = filters == null ? void 0 : filters.map) == null ? void 0 : _a2.call(filters, (filter) => {
9803
+ let allowedFiltersCollectionId = (_c2 = (_b3 = (_a3 = filters == null ? void 0 : filters.map) == null ? void 0 : _a3.call(filters, (filter) => {
9721
9804
  const { active, collections, items } = filter;
9722
9805
  if (!active)
9723
9806
  return;
@@ -9727,7 +9810,7 @@ const SearchResultWidget = (props) => {
9727
9810
  } else {
9728
9811
  return;
9729
9812
  }
9730
- })) == null ? void 0 : _b2.filter) == null ? void 0 : _c2.call(_b2, (item) => item);
9813
+ })) == null ? void 0 : _b3.filter) == null ? void 0 : _c2.call(_b3, (item) => item);
9731
9814
  let allowedFiltersCollectionAll = (_f2 = (_e2 = (_d2 = filters == null ? void 0 : filters.map) == null ? void 0 : _d2.call(filters, (filter) => {
9732
9815
  const { active, collections, items } = filter;
9733
9816
  if (!active)
@@ -9776,7 +9859,7 @@ const SearchResultWidget = (props) => {
9776
9859
  let responseGeneral;
9777
9860
  let getFirstIndex;
9778
9861
  response = instantSearchPreviewSettings || JSON.parse(LOCAL_STORAGE_INSTANT_SEARCH_SETTING);
9779
- responseGeneral = generalPreviewSettings || JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
9862
+ responseGeneral = generalPreviewSettings || JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.GENERAL_SETTING) || null);
9780
9863
  if (!response)
9781
9864
  return;
9782
9865
  setInstantSearchSettings(response);
@@ -9826,7 +9909,7 @@ const SearchResultWidget = (props) => {
9826
9909
  valueDefaultSort = (_e2 = valueAllowedSorts == null ? void 0 : valueAllowedSorts[0]) == null ? void 0 : _e2.value;
9827
9910
  }
9828
9911
  setDefaultSort(valueDefaultSort);
9829
- setDefaultLimit(instantSearchPreviewSettings ? limit : (localStorage == null ? void 0 : localStorage.getItem(LOCAL_STORAGE_KEY.LIMIT_PRODUCT)) || limit);
9912
+ setDefaultLimit(instantSearchPreviewSettings ? limit : safeGetItem(LOCAL_STORAGE_KEY.LIMIT_PRODUCT) || limit);
9830
9913
  setLanguageSettings(languages);
9831
9914
  setHierarchicalProductTypeSettings(hierarchical_product_type);
9832
9915
  setHierarchicalCollectionsSettings(hierarchical_collections);
@@ -9883,13 +9966,13 @@ const SearchResultWidget = (props) => {
9883
9966
  window.history.replaceState(null, "", `${document.location.pathname}?${searchParams2.toString()}`);
9884
9967
  }, []);
9885
9968
  const initStates = () => {
9886
- const INSTANT_SEARCH_SETTING = instantSearchPreviewSettings || JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
9969
+ const INSTANT_SEARCH_SETTING = instantSearchPreviewSettings || JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
9887
9970
  if (INSTANT_SEARCH_SETTING)
9888
9971
  handleInitStates(INSTANT_SEARCH_SETTING);
9889
9972
  };
9890
9973
  useEffectOnChange(() => {
9891
9974
  handleSettings({
9892
- LOCAL_STORAGE_INSTANT_SEARCH_SETTING: localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null,
9975
+ LOCAL_STORAGE_INSTANT_SEARCH_SETTING: safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null,
9893
9976
  isPreviewSettings: true
9894
9977
  });
9895
9978
  }, [previewSettings]);
@@ -9899,7 +9982,7 @@ const SearchResultWidget = (props) => {
9899
9982
  return;
9900
9983
  initStates();
9901
9984
  handleSettings({
9902
- LOCAL_STORAGE_INSTANT_SEARCH_SETTING: localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null
9985
+ LOCAL_STORAGE_INSTANT_SEARCH_SETTING: safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null
9903
9986
  });
9904
9987
  if (typeof window !== "undefined") {
9905
9988
  if (layoutType === "default") {
@@ -10543,7 +10626,7 @@ const ResultProduct = React__default.memo((props) => {
10543
10626
  const searchParams2 = new URLSearchParams(document.location.search);
10544
10627
  searchParams2.set(queryLimit, String(value));
10545
10628
  setClickedLimitId(Number(value));
10546
- localStorage == null ? void 0 : localStorage.setItem(LOCAL_STORAGE_KEY.LIMIT_PRODUCT, value);
10629
+ safeSetItem(LOCAL_STORAGE_KEY.LIMIT_PRODUCT, String(value));
10547
10630
  if (!objectPresent(previewSettings))
10548
10631
  window.history.replaceState(null, "", `${document.location.pathname}?${searchParams2.toString()}`);
10549
10632
  }, []);
@@ -10666,7 +10749,7 @@ const ResultProduct = React__default.memo((props) => {
10666
10749
  const handleSearchResultData = async (props2) => {
10667
10750
  var _a2, _b2;
10668
10751
  const { isLoadMore: isLoadMore2 = false, result: resultProp, onSearch } = props2;
10669
- const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
10752
+ const INSTANT_SEARCH_SETTING = JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
10670
10753
  const { index_product } = INSTANT_SEARCH_SETTING || {};
10671
10754
  const isNoneFacetSelected = Boolean(!((_a2 = handleDataClickedFacets()) == null ? void 0 : _a2.length));
10672
10755
  const isFirstTimeOrOnSearch = handleSearchResultFirstTime && initStatesFirstTime || onSearch;
@@ -10685,8 +10768,8 @@ const ResultProduct = React__default.memo((props) => {
10685
10768
  let isCurrentIndex = index.includes(clickedTabIndexId);
10686
10769
  let tabTotal = isCurrentIndex ? totalHits : total;
10687
10770
  if (layoutType === "default" && ((_a3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _a3.length)) {
10688
- const { totalHits: totalHits2 } = (_c2 = (_b3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _b3.find) == null ? void 0 : _c2.call(_b3, ({ indexUid }) => indexUid.includes(index));
10689
- tabTotal = totalHits2 || tabTotal;
10771
+ const { totalHits: totalHitsFromIndex } = ((_c2 = (_b3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _b3.find) == null ? void 0 : _c2.call(_b3, ({ indexUid }) => indexUid.includes(index))) || {};
10772
+ tabTotal = totalHitsFromIndex ?? tabTotal;
10690
10773
  }
10691
10774
  return {
10692
10775
  ...tab,
@@ -11408,7 +11491,7 @@ const ResultCategory = React__default.memo((props) => {
11408
11491
  const handleSearchResultData = (props2) => {
11409
11492
  var _a;
11410
11493
  const { isReplaceData = false, result: resultProp, onSearch } = props2;
11411
- const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
11494
+ const INSTANT_SEARCH_SETTING = JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
11412
11495
  const handleSearchResultFirstTime = isFirstLoading;
11413
11496
  const isFirstTimeOrOnSearch = handleSearchResultFirstTime && initStatesFirstTime || onSearch;
11414
11497
  const resultData = isFirstTimeOrOnSearch ? resultProp == null ? void 0 : resultProp.results : resultProp;
@@ -11713,13 +11796,13 @@ const SearchWidget = (props) => {
11713
11796
  await handleMultiSearch(response);
11714
11797
  };
11715
11798
  useEffectOnChange(() => {
11716
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
11799
+ handleSettings(safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
11717
11800
  }, [previewSettings]);
11718
11801
  React__default.useEffect(() => {
11719
11802
  var _a2, _b2;
11720
11803
  if (!isRenderAppInstantSearch)
11721
11804
  return;
11722
- handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
11805
+ handleSettings(safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
11723
11806
  if (typeof window !== "undefined") {
11724
11807
  if ((_b2 = (_a2 = window == null ? void 0 : window.sledge) == null ? void 0 : _a2.instantSearch) == null ? void 0 : _b2.searchWidget)
11725
11808
  window.sledge.instantSearch.searchWidget.search = (keyword2 = "") => {
@@ -11732,7 +11815,7 @@ const SearchWidget = (props) => {
11732
11815
  }
11733
11816
  }, [isRenderAppInstantSearch]);
11734
11817
  useEffectOnChange(() => {
11735
- const INSTANT_SEARCH_SETTING = instantSearchPreviewSettings || JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
11818
+ const INSTANT_SEARCH_SETTING = instantSearchPreviewSettings || JSON.parse(safeGetItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
11736
11819
  setShowSearchResult(keyword ? true : false);
11737
11820
  if (INSTANT_SEARCH_SETTING)
11738
11821
  handleMultiSearch(INSTANT_SEARCH_SETTING, true);