c6fe65ad99
Root cause 1 (count doubling): LogoutButton never cleared the local cart, and mergeServerCartIntoLocal() (called on login) adds server quantities into the existing local ones rather than replacing — since CartSync mirrors local to the server continuously, local and server already held the same quantities at logout time, so every login added them together, doubling the count each cycle. Fix: clear the local cart on logout, so the next login's merge starts from empty (or only genuine guest-session additions) instead of re-adding already-synced quantities. Root cause 2 (page couldn't load): readCart()/getCart() only guarded against JSON.parse syntax errors, not against the parsed value being a non-array — once localStorage held a corrupted (inflated/malformed) value, CartContent.tsx's cart.map() threw uncaught during render. Fix: validate Array.isArray() after parsing, falling back to []. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>