@pradip1995/segment-product-card 0.3.10 → 0.3.12

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pradip1995/segment-product-card",
3
- "version": "0.3.10",
3
+ "version": "0.3.12",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -17,15 +17,19 @@
17
17
  "./product-scroll": "./src/product-scroll.tsx",
18
18
  "./product-rail-variants": "./src/product-rail-variants.tsx"
19
19
  },
20
+ "scripts": {
21
+ "typecheck": "tsc --noEmit",
22
+ "lint": "tsc --noEmit"
23
+ },
20
24
  "peerDependencies": {
21
25
  "@pradip1995/commerce-core": "^4.0.0",
22
26
  "@pradip1995/plugin-sdk": "^0.2.0",
27
+ "next": ">=15",
23
28
  "react": ">=19",
24
- "react-dom": ">=19",
25
- "next": ">=15"
29
+ "react-dom": ">=19"
26
30
  },
27
31
  "dependencies": {
28
- "@pradip1995/segment-primitives": "^0.4.0",
32
+ "@pradip1995/segment-primitives": "^0.4.2",
29
33
  "@pradip1995/segment-tokens": "^0.3.7"
30
34
  },
31
35
  "devDependencies": {
@@ -33,9 +37,5 @@
33
37
  "@types/react": "^19",
34
38
  "react": "19.0.3",
35
39
  "typescript": "^5.7.2"
36
- },
37
- "scripts": {
38
- "typecheck": "tsc --noEmit",
39
- "lint": "tsc --noEmit"
40
40
  }
41
- }
41
+ }
@@ -9,6 +9,7 @@ import {
9
9
  removeFromWishlist,
10
10
  } from "@pradip1995/commerce-core/client/actions/wishlist"
11
11
  import type { HttpTypes } from "@medusajs/types"
12
+ import { isNextRedirect } from "@pradip1995/segment-primitives/is-next-redirect"
12
13
  import QuickAddPanel from "./quick-add-panel"
13
14
 
14
15
  type Props = {
@@ -52,14 +53,11 @@ export default function ProductCardActions({ product, countryCode, wishlistProdu
52
53
  useEffect(() => {
53
54
  if (!product.id) return
54
55
 
56
+ // Prefer server-provided IDs. Do not fan out getWishlistProductIds() per card
57
+ // on home — resolve lazily on first heart click when IDs were not passed.
55
58
  if (wishlistProductIds !== undefined) {
56
59
  setWishlisted(wishlistProductIds.includes(product.id))
57
- return
58
60
  }
59
-
60
- getWishlistProductIds()
61
- .then((ids) => setWishlisted(ids.includes(product.id!)))
62
- .catch(() => {})
63
61
  }, [product.id, wishlistProductIds])
64
62
 
65
63
  useEffect(() => {
@@ -91,12 +89,24 @@ export default function ProductCardActions({ product, countryCode, wishlistProdu
91
89
 
92
90
  setWishlistLoading(true)
93
91
  try {
94
- const result = wishlisted
92
+ // Lazy-resolve wishlist state when layout did not pass IDs (anonymous / slim layout).
93
+ let currentlyWishlisted = wishlisted
94
+ if (wishlistProductIds === undefined) {
95
+ try {
96
+ const ids = await getWishlistProductIds()
97
+ currentlyWishlisted = ids.includes(product.id)
98
+ setWishlisted(currentlyWishlisted)
99
+ } catch {
100
+ currentlyWishlisted = false
101
+ }
102
+ }
103
+
104
+ const result = currentlyWishlisted
95
105
  ? await removeFromWishlist(product.id)
96
106
  : await addToWishlist(product.id)
97
107
 
98
108
  if (result.success) {
99
- setWishlisted(!wishlisted)
109
+ setWishlisted(!currentlyWishlisted)
100
110
  router.refresh()
101
111
  return
102
112
  }
@@ -125,6 +135,7 @@ export default function ProductCardActions({ product, countryCode, wishlistProdu
125
135
  setShowQuickAdd(false)
126
136
  router.refresh()
127
137
  } catch (err) {
138
+ if (isNextRedirect(err)) throw err
128
139
  const message = err instanceof Error ? err.message : "Could not add to cart"
129
140
  setError(message)
130
141
  window.dispatchEvent(