Shopping cart persists across browser sessions
Why it matters
Carts stored only in React useState or non-persisted Zustand evaporate on refresh, tab close, and session timeout. Shoppers who added three items, got distracted, and returned thirty minutes later see an empty cart and abandon. Baymard Institute pegs abandonment around 70%, and volatile cart state compounds every other UX issue in this bundle. Lost cart data is lost revenue, and it disproportionately hurts mobile shoppers whose browsers aggressively reclaim memory.
Severity rationale
Critical because a cart that empties on refresh directly causes purchase abandonment and revenue loss on every session.
Remediation
Write cart state to localStorage on every mutation and hydrate from it on mount in src/hooks/useCart.ts. For logged-in users, sync to a persistent backend through src/app/api/cart/route.ts so the cart survives device switches. Do not gate persistence behind if (user) with no anonymous fallback.
const [cart, setCart] = useState(() => JSON.parse(localStorage.getItem('cart') ?? '[]'))
useEffect(() => { localStorage.setItem('cart', JSON.stringify(cart)) }, [cart])
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the Cart & Checkout UX Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
Taxons
History
- 2026-04-18·v1.0.0·Initial import from ecommerce-cart-ux·automated