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 _bgCover = _firstAlbums[0] ? coverUrl(_firstAlbums[0].coverArt, 512) : null;
|
||||||
const bgSrc = img || _bgCover;
|
const bgSrc = img || _bgCover;
|
||||||
|
|
||||||
// Reveal when images are ready; color tint fades in after (non-blocking)
|
const _revealHero = () => requestAnimationFrame(() => {
|
||||||
let _pfpReady = false, _bgReady = false;
|
hero.style.transition = 'opacity 0.25s ease';
|
||||||
const _revealHero = () => {
|
hero.style.opacity = '1';
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(img) {
|
if(img) {
|
||||||
|
if(bgSrc) hero.style.background = '';
|
||||||
|
const bgEl = document.getElementById('artist-hero-bg');
|
||||||
const pfpWrap = document.getElementById('artist-hero-pfp-wrap');
|
const pfpWrap = document.getElementById('artist-hero-pfp-wrap');
|
||||||
if(pfpWrap) {
|
if(pfpWrap) {
|
||||||
const pfpImg = document.createElement('img');
|
const pfpImg = document.createElement('img');
|
||||||
pfpImg.className = 'artist-hero-pfp';
|
pfpImg.className = 'artist-hero-pfp';
|
||||||
pfpImg.alt = '';
|
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;
|
pfpImg.src = img;
|
||||||
pfpWrap.prepend(pfpImg);
|
pfpWrap.prepend(pfpImg);
|
||||||
document.getElementById('artist-hero-pfp-initial')?.style.setProperty('display', 'none');
|
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 => {
|
_extractColor(img).then(rgb => {
|
||||||
if(!rgb) return;
|
if(!rgb) return;
|
||||||
const [r, g, b] = rgb;
|
const [r, g, b] = rgb;
|
||||||
@@ -164,7 +152,15 @@ export async function loadArtistDetail(artist) {
|
|||||||
if(overlay) hero.insertBefore(tint, overlay);
|
if(overlay) hero.insertBefore(tint, overlay);
|
||||||
requestAnimationFrame(() => { tint.style.opacity = '1'; });
|
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 ──
|
// ── Bio ──
|
||||||
const info = infoRes.status === 'fulfilled' ? infoRes.value?.artistInfo2 : null;
|
const info = infoRes.status === 'fulfilled' ? infoRes.value?.artistInfo2 : null;
|
||||||
|
|||||||
Reference in new issue
Block a user