@anker-in/shopify-react 0.1.1-beta.17 → 0.1.1-beta.19

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.
@@ -477,18 +477,24 @@ var useCalcAutoFreeGift = (cart, autoFreeGiftConfig, customer, lines) => {
477
477
  }
478
478
  return true;
479
479
  }, [giftHandles]);
480
- const { data: giftProductsResult } = useSWR(shouldFetch ? giftHandles : null, async () => {
481
- const res = await getProductsByHandles(client, {
482
- handles: giftHandles,
483
- locale
484
- });
485
- const result = Array.isArray(res) ? res : [];
486
- giftProductsCache.current = {
487
- data: result,
488
- giftHandles: [...giftHandles]
489
- };
490
- return result;
491
- });
480
+ const { data: giftProductsResult } = useSWR(
481
+ shouldFetch ? giftHandles : null,
482
+ async () => {
483
+ const res = await getProductsByHandles(client, {
484
+ handles: giftHandles,
485
+ locale
486
+ });
487
+ const result = Array.isArray(res) ? res : [];
488
+ giftProductsCache.current = {
489
+ data: result,
490
+ giftHandles: [...giftHandles]
491
+ };
492
+ return result;
493
+ },
494
+ {
495
+ revalidateOnFocus: false
496
+ }
497
+ );
492
498
  const finalGiftProductsResult = useMemo(() => {
493
499
  if (giftProductsCache.current && !shouldFetch) {
494
500
  return giftProductsCache.current.data || void 0;
@@ -541,12 +547,14 @@ var useScriptAutoFreeGift = ({
541
547
  upgrade_multiple2 = 1.2;
542
548
  upgrade_value2 = 40;
543
549
  }
544
- effectiveCart?.lineItems?.forEach(({ customAttributes }) => {
545
- customAttributes?.forEach(({ key, value }) => {
546
- if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
547
- if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
548
- });
549
- });
550
+ effectiveCart?.lineItems?.forEach(
551
+ ({ customAttributes }) => {
552
+ customAttributes?.forEach(({ key, value }) => {
553
+ if (key === "_amount_upgrade_multiple") upgrade_multiple2 = Number(value) || 1;
554
+ if (key === "_amount_upgrade_value") upgrade_value2 = Number(value) || 0;
555
+ });
556
+ }
557
+ );
550
558
  return [upgrade_multiple2, upgrade_value2];
551
559
  }, [effectiveCart?.lineItems, points_subscribe]);
552
560
  const breakpoints = useMemo(() => {
@@ -611,18 +619,24 @@ var useScriptAutoFreeGift = ({
611
619
  const nextLevel = levelIndex > 0 ? sortedLevels[levelIndex - 1] ?? null : null;
612
620
  return [currentLevel, nextLevel];
613
621
  }, [breakpoints, involvedSubTotal, involvedLines.length]);
614
- const { data: giftProductsResult } = useSWR(shouldFetch ? giftHandles : null, async () => {
615
- const res = await getProductsByHandles(client, {
616
- handles: giftHandles,
617
- locale
618
- });
619
- const result = Array.isArray(res) ? res : [];
620
- giftProductsCache.current = {
621
- data: result,
622
- giftHandles: [...giftHandles]
623
- };
624
- return result;
625
- });
622
+ const { data: giftProductsResult } = useSWR(
623
+ shouldFetch ? giftHandles : null,
624
+ async () => {
625
+ const res = await getProductsByHandles(client, {
626
+ handles: giftHandles,
627
+ locale
628
+ });
629
+ const result = Array.isArray(res) ? res : [];
630
+ giftProductsCache.current = {
631
+ data: result,
632
+ giftHandles: [...giftHandles]
633
+ };
634
+ return result;
635
+ },
636
+ {
637
+ revalidateOnFocus: false
638
+ }
639
+ );
626
640
  const finalGiftProductsResult = useMemo(() => {
627
641
  if (giftProductsCache.current && !shouldFetch) {
628
642
  return giftProductsCache.current.data || void 0;
@@ -844,8 +858,29 @@ var useCartAttributes = ({
844
858
  [memberAttributes, functionAttributes, presellAttributes, weightAttributes, trackingAttributes]
845
859
  );
846
860
  const extraAttributesInCart = useMemo(() => {
861
+ const commonAttributeKeys = [
862
+ // member attributes
863
+ "_token",
864
+ "_member_type",
865
+ "_user_type",
866
+ "_is_login",
867
+ "_login_user",
868
+ // function attributes
869
+ "_discounts_function_env",
870
+ // presell attributes
871
+ "_presale",
872
+ // weight attributes
873
+ "_weight",
874
+ "_app_source_name",
875
+ // tracking attributes
876
+ "utm_params",
877
+ // referral attributes
878
+ "_invite_code",
879
+ "_play_mode_id",
880
+ "_popup"
881
+ ];
847
882
  return cart?.customAttributes?.filter(
848
- (item) => !commonAttributes.some((attr) => attr.key === item.key)
883
+ (item) => !commonAttributeKeys.includes(item.key)
849
884
  ) || [];
850
885
  }, [cart]);
851
886
  return useMemo(
@@ -1070,7 +1105,12 @@ function CartProvider({
1070
1105
  const { attributes } = useCartAttributes({ profile, customer, cart, memberSetting });
1071
1106
  useRequest(
1072
1107
  () => {
1073
- const newAttributes = [...attributes, ...customAttributes];
1108
+ const newAttributes = [...attributes];
1109
+ customAttributes.forEach((item) => {
1110
+ if (item.value && !newAttributes.some((attr) => attr.key === item.key)) {
1111
+ newAttributes.push(item);
1112
+ }
1113
+ });
1074
1114
  const needUpdate = cart && checkAttributesUpdateNeeded(
1075
1115
  cart.customAttributes,
1076
1116
  newAttributes,