From f34d35b9c4d8767dc63e21592dd512dcba25cb2b Mon Sep 17 00:00:00 2001 From: giles Date: Tue, 24 Feb 2026 12:52:19 +0000 Subject: [PATCH] Fix cart icon vanishing on add-to-cart when fragment fetch fails When the cart-mini fragment fetch returns empty, the HTMX outerHTML swap was replacing #cart-mini with nothing. Now falls back to the local _mini.html macro with count from g.cart. Co-Authored-By: Claude Opus 4.6 --- templates/_types/product/_added.html | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/templates/_types/product/_added.html b/templates/_types/product/_added.html index ad44b9d..3005e4e 100644 --- a/templates/_types/product/_added.html +++ b/templates/_types/product/_added.html @@ -1,8 +1,13 @@ {# HTMX response after add-to-cart: OOB-swap the mini cart + product buttons #} {% import '_types/product/_cart.html' as _cart %} -{# 1. Update mini cart via cart-mini fragment #} -{{ cart_mini_html | safe }} +{# 1. Update mini cart via cart-mini fragment (fallback to local macro) #} +{% if cart_mini_html %} + {{ cart_mini_html | safe }} +{% else %} + {% from '_types/cart/_mini.html' import mini with context %} + {{ mini(count=cart | sum(attribute="quantity")) }} +{% endif %} {# 2. Update add/remove buttons on the product #} {{ _cart.add(d.slug, cart, oob='true') }}