fix: hero reveal — set bg inside pfp onload so cache is warm, no state machine
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
55cfaf0392
commit
c3d0360946
1 file changed
+22
-26
+22
-26
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user