Fix cart page error when reading designJson
Handle designJson as either string or object, parse if needed. Prevents TypeError when accessing front/back properties. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 4.5
parent
548046d4bf
commit
f72e934943
@@ -12,7 +12,14 @@ export default function CartPage() {
|
|||||||
const removeItem = useCart((s) => s.removeItem);
|
const removeItem = useCart((s) => s.removeItem);
|
||||||
const setQuantity = useCart((s) => s.setQuantity);
|
const setQuantity = useCart((s) => s.setQuantity);
|
||||||
const total = useCart((s) => s.total());
|
const total = useCart((s) => s.total());
|
||||||
const hasCustomDesign = items.some((item) => item.designJson.front.length > 0 || item.designJson.back.length > 0);
|
const hasCustomDesign = items.some((item) => {
|
||||||
|
try {
|
||||||
|
const design = typeof item.designJson === 'string' ? JSON.parse(item.designJson) : item.designJson;
|
||||||
|
return (design.front?.length ?? 0) > 0 || (design.back?.length ?? 0) > 0;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
useEffect(() => setMounted(true), []);
|
useEffect(() => setMounted(true), []);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user