Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

feat(marketplace): show the initial-letter fallback instead of a blank box when R2 thumbnails/GLBs fail to load

nirholasd152edbfe6aa
diff --git a/src/marketplace-detail.js b/src/marketplace-detail.js
index b795c0a0e..b3ada88a0 100644
--- a/src/marketplace-detail.js
+++ b/src/marketplace-detail.js
@@ -52,6 +52,47 @@ function fmtNumber(n) {
// ── Detail header avatar ────────────────────────────────────────────────
+// Loads a thumbnail into an element's background only once the image has
+// actually decoded. Object storage (R2) can 403/502 behind a URL that still
+// looks valid, and a raw `background-image: url(...)` on a dead asset just
+// renders a blank box with no signal to the user, so this probes with a
+// detached Image() first and leaves the initial-letter fallback in place on
+// failure instead of swapping to it.
+function loadThumbnailBackground(el, url) {
+ const fallback = el.querySelector('.d-avatar-fallback');
+ const probe = new Image();
+ probe.onload = () => {
+ el.classList.add('has-img');
+ el.style.backgroundImage = `url('${url}')`;
+ if (fallback) fallback.style.display = 'none';
+ };
+ probe.onerror = () => {
+ // Object storage is unreachable for this asset: keep showing the
+ // initial-letter fallback rather than a blank image box.
+ };
+ probe.src = url;
+}
+
+// Same probe-before-swap treatment for a grid of small thumbnail cards (the
+// creator modal's agents/avatars grids): each `.thumb` renders its
+// fallback letter up front, and only gets a background image once that
+// image has actually decoded.
+function wireThumbGrid(container) {
+ container.querySelectorAll('.thumb[data-thumb-url]').forEach((el) => {
+ const url = el.dataset.thumbUrl;
+ if (!url) return;
+ const probe = new Image();
+ probe.onload = () => {
+ el.style.backgroundImage = `url('${url}')`;
+ el.querySelector('.thumb-fallback-text')?.remove();
+ };
+ probe.onerror = () => {
+ // Leave the fallback letter/glyph showing.
+ };
+ probe.src = url;
+ });
+}
+
export function renderDetailAvatar(a) {
const el = $('d-avatar');
if (!el) return;
@@ -60,6 +101,10 @@ export function renderDetailAvatar(a) {
const fallback = el.querySelector('.d-avatar-fallback');
const existingMv = el.querySelector('model-viewer');
if (existingMv) existingMv.remove();
+ if (fallback) {
+ fallback.textContent = initial(a.name);
+ fallback.style.display = 'flex';
+ }
if (a.avatar_glb_url) {
el.classList.add('has-3d');
@@ -76,15 +121,18 @@ export function renderDetailAvatar(a) {
mv.setAttribute('shadow-intensity', '0.4');
mv.setAttribute('tone-mapping', 'aces');
mv.setAttribute('loading', 'eager');
+ mv.addEventListener(
+ 'error',
+ () => {
+ mv.remove();
+ el.classList.remove('has-3d');
+ if (a.thumbnail_url) loadThumbnailBackground(el, a.thumbnail_url);
+ },
+ { once: true },
+ );
el.appendChild(mv);
- if (fallback) fallback.style.display = 'none';
} else if (a.thumbnail_url) {
- el.classList.add('has-img');
- el.style.backgroundImage = `url('${a.thumbnail_url}')`;
- if (fallback) fallback.style.display = 'none';
- } else if (fallback) {
- fallback.textContent = initial(a.name);
- fallback.style.display = 'flex';
+ loadThumbnailBackground(el, a.thumbnail_url);
}
}
@@ -494,9 +542,10 @@ function renderCreatorModal(payload, deps) {
agentsGrid.innerHTML = '<div class="market-empty">No published agents yet.</div>';
} else {
agentsGrid.innerHTML = agents.map((a) => {
- const thumb = a.thumbnail_url
- ? `<div class="thumb" style="background-image:url('${escapeHtml(a.thumbnail_url)}')"></div>`
- : `<div class="thumb">${escapeHtml(initial(a.name))}</div>`;
+ // Fallback letter renders immediately; wireThumbGrid() below swaps in
+ // the background image only once it has actually decoded, so a dead
+ // R2 asset shows the letter instead of a blank box.
+ const thumb = `<div class="thumb" data-thumb-url="${a.thumbnail_url ? escapeHtml(a.thumbnail_url) : ''}"><span class="thumb-fallback-text">${escapeHtml(initial(a.name))}</span></div>`;
// Non-link badge: the whole card is clickable (navigates to the agent),
// so a nested explorer anchor would double-fire. The explorer link lives
// on the agent detail page this card opens.
@@ -513,6 +562,7 @@ function renderCreatorModal(payload, deps) {
</div>`;
}).join('');
wireWalletChips(agentsGrid);
+ wireThumbGrid(agentsGrid);
agentsGrid.querySelectorAll('[data-agent-id]').forEach((card) => {
card.addEventListener('click', () => {
closeCreatorModal();
@@ -527,9 +577,7 @@ function renderCreatorModal(payload, deps) {
avatarsGrid.innerHTML = '<div class="market-empty">No public avatars yet.</div>';
} else {
avatarsGrid.innerHTML = avatars.map((avt) => {
- const thumb = avt.thumbnail_url
- ? `<div class="thumb" style="background-image:url('${escapeHtml(avt.thumbnail_url)}')"></div>`
- : `<div class="thumb">◉</div>`;
+ const thumb = `<div class="thumb" data-thumb-url="${avt.thumbnail_url ? escapeHtml(avt.thumbnail_url) : ''}"><span class="thumb-fallback-text">◉</span></div>`;
const wallet = walletChipHTML(avt, { isOwner: false, showPending: false, link: false });
return `<div class="creator-mini-card" data-avatar-id="${escapeHtml(avt.id)}">
${thumb}
@@ -539,6 +587,7 @@ function renderCreatorModal(payload, deps) {
</div>`;
}).join('');
wireWalletChips(avatarsGrid);
+ wireThumbGrid(avatarsGrid);
avatarsGrid.querySelectorAll('[data-avatar-id]').forEach((card) => {
card.addEventListener('click', () => {
const avt = avatars.find((x) => x.id === card.dataset.avatarId);
diff --git a/src/marketplace-gallery.js b/src/marketplace-gallery.js
index 5cd1c30b5..7f43e1342 100644
--- a/src/marketplace-gallery.js
+++ b/src/marketplace-gallery.js
@@ -801,11 +801,15 @@ export function createMarketplaceGallery({ scene, getLocalPosition }) {
});
}
+ function panelFallbackHTML(listing, accent) {
+ return `<div class="mwg-panel-fallback" style="background:linear-gradient(160deg,${accent},#0c0c0e)">${escapeHtml((listing.name || '?').charAt(0).toUpperCase())}</div>`;
+ }
+
function showPanel(listing) {
const accent = TYPE_ACCENT[listing.type] || '#fafafa';
const media = listing.image
? `<img src="${escapeAttr(listing.image)}" alt="" loading="lazy" />`
- : `<div class="mwg-panel-fallback" style="background:linear-gradient(160deg,${accent},#0c0c0e)">${escapeHtml((listing.name || '?').charAt(0).toUpperCase())}</div>`;
+ : panelFallbackHTML(listing, accent);
// Trust signals — ratings + adoption counts pulled straight from the same
// listing rows the grid uses, so a number never disagrees across surfaces.
@@ -861,6 +865,19 @@ export function createMarketplaceGallery({ scene, getLocalPosition }) {
<p class="mwg-panel-hint">Press <kbd>E</kbd> to open</p>
</div>`;
+ // An R2 asset can 403/502 behind a URL that still looked valid when the
+ // listing loaded. A broken <img> would otherwise sit there as the
+ // browser's own broken-image glyph; swap in the same designed fallback
+ // the no-image case uses instead.
+ const panelImg = panel.querySelector('.mwg-panel-media img');
+ panelImg?.addEventListener(
+ 'error',
+ () => {
+ panelImg.outerHTML = panelFallbackHTML(listing, accent);
+ },
+ { once: true },
+ );
+
// Plain left-click routes through the shared nav guard; modified clicks
// (⌘/ctrl/middle → new tab) fall through to the native anchor.
panel.querySelector('.mwg-panel-cta')?.addEventListener('click', (e) => {