Skip to content

Commit f93ca8a

Browse files
committed
auto-retry product images
1 parent eadbe92 commit f93ca8a

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

src/lib/lttstore/LTTProductCard.svelte

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
let goneInHours = $derived((stock?.total ?? -1) / (purchasesPerHour ?? -1));
2323
2424
let handle = $derived(productRedirects[product.handle] ?? product.handle);
25+
let imageReload = $state(0)
2526
let imageSrc = $derived(
2627
(dev ? 'https://whenplane.com' : '') +
2728
'/cdn-cgi/image/anim=false,fit=scale-down,width=528,metadata=copyright,q=60,sqc=50,format=auto/' +
@@ -43,6 +44,14 @@
4344
alt={title}
4445
loading={lazyLoadImage ? 'lazy' : undefined}
4546
decoding="async"
47+
onerror={() => {
48+
let delay = Math.pow(2, imageReload) - 1;
49+
if(delay === 0) {
50+
imageReload++;
51+
} else {
52+
setTimeout(() => imageReload++, delay);
53+
}
54+
}}
4655
/>
4756
{:else}
4857
No featured image

0 commit comments

Comments
 (0)