From c3d0360946331063180ee6f1470a9b3fb44297c8 Mon Sep 17 00:00:00 2001 From: Honey Date: Sun, 7 Jun 2026 22:51:13 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20hero=20reveal=20=E2=80=94=20set=20bg=20i?= =?UTF-8?q?nside=20pfp=20onload=20so=20cache=20is=20warm,=20no=20state=20m?= =?UTF-8?q?achine?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 4.6 --- src/views/detail.js | 48 +++++++++++++++++++++------------------------ 1 file changed, 22 insertions(+), 26 deletions(-) diff --git a/src/views/detail.js b/src/views/detail.js index 37f9ce9..79a2392 100644 --- a/src/views/detail.js +++ b/src/views/detail.js @@ -119,41 +119,29 @@ export async function loadArtistDetail(artist) { const _bgCover = _firstAlbums[0] ? coverUrl(_firstAlbums[0].coverArt, 512) : null; const bgSrc = img || _bgCover; - // Reveal when images are ready; color tint fades in after (non-blocking) - let _pfpReady = false, _bgReady = false; - const _revealHero = () => { - if(!_pfpReady || !_bgReady) return; - requestAnimationFrame(() => { hero.style.transition = 'opacity 0.25s ease'; hero.style.opacity = '1'; }); - }; - - if(bgSrc) { - hero.style.background = ''; - const bgEl = document.getElementById('artist-hero-bg'); - if(bgSrc === img) { - // same URL as pfp — browser cache will have it when pfp loads, no extra request - bgEl.style.backgroundImage = `url('${bgSrc}')`; - _bgReady = true; - } else { - const _bgPreload = new Image(); - _bgPreload.onload = _bgPreload.onerror = () => { bgEl.style.backgroundImage = `url('${bgSrc}')`; _bgReady = true; _revealHero(); }; - _bgPreload.src = bgSrc; - } - } else { - _bgReady = true; - } + const _revealHero = () => requestAnimationFrame(() => { + hero.style.transition = 'opacity 0.25s ease'; + hero.style.opacity = '1'; + }); if(img) { + if(bgSrc) hero.style.background = ''; + const bgEl = document.getElementById('artist-hero-bg'); const pfpWrap = document.getElementById('artist-hero-pfp-wrap'); if(pfpWrap) { const pfpImg = document.createElement('img'); pfpImg.className = 'artist-hero-pfp'; pfpImg.alt = ''; - pfpImg.onload = pfpImg.onerror = () => { _pfpReady = true; _revealHero(); }; + pfpImg.onload = pfpImg.onerror = () => { + // image is now in cache — set bg background-image here so it renders instantly + if(bgEl && bgSrc) bgEl.style.backgroundImage = `url('${bgSrc}')`; + _revealHero(); + }; pfpImg.src = img; pfpWrap.prepend(pfpImg); document.getElementById('artist-hero-pfp-initial')?.style.setProperty('display', 'none'); - } else { _pfpReady = true; } - // color tint is non-blocking — fades in via CSS whenever it's ready + } + // color tint — non-blocking, fades in via CSS _extractColor(img).then(rgb => { if(!rgb) return; const [r, g, b] = rgb; @@ -164,7 +152,15 @@ export async function loadArtistDetail(artist) { if(overlay) hero.insertBefore(tint, overlay); requestAnimationFrame(() => { tint.style.opacity = '1'; }); }); - } else { _pfpReady = true; _revealHero(); } + } else if(bgSrc) { + hero.style.background = ''; + const bgEl = document.getElementById('artist-hero-bg'); + const _pre = new Image(); + _pre.onload = _pre.onerror = () => { if(bgEl) bgEl.style.backgroundImage = `url('${bgSrc}')`; _revealHero(); }; + _pre.src = bgSrc; + } else { + _revealHero(); + } // ── Bio ── const info = infoRes.status === 'fulfilled' ? infoRes.value?.artistInfo2 : null;