fix(artist): bio truncation reactivity, adjust margins

- Observe parent container for resize (not clamped element)
- Double RAF ensures CSS applies before measurement
- top-tracks-section: margin-top 32px
- artist-header: margin-bottom 22px
This commit is contained in:
vicrodh committed 2026-01-23 20:51:09 -06:00
1 parent f19081ee1d
commit e404048c5b
1 file changed
+21 -11
@@ -577,6 +577,7 @@
// Smart 3-line truncation with resize detection // Smart 3-line truncation with resize detection
let bioTextEl = $state<HTMLDivElement | null>(null); let bioTextEl = $state<HTMLDivElement | null>(null);
let bioContainerEl = $state<HTMLDivElement | null>(null);
let isBioTruncated = $state(false); let isBioTruncated = $state(false);
function checkBioTruncation() { function checkBioTruncation() {
@@ -586,19 +587,26 @@
} }
$effect(() => { $effect(() => {
if (!bioTextEl || !bioText) return; if (!bioTextEl || !bioText || !bioContainerEl) return;
// Initial check // Initial check after a frame to ensure layout is complete
checkBioTruncation(); requestAnimationFrame(() => {
checkBioTruncation();
});
// Observe resize to recalculate when container width changes // Observe the PARENT container (not the clamped element) for width changes
const observer = new ResizeObserver(() => { const observer = new ResizeObserver(() => {
if (!bioExpanded) { if (!bioExpanded) {
checkBioTruncation(); // Double RAF to ensure CSS has applied after resize
requestAnimationFrame(() => {
requestAnimationFrame(() => {
checkBioTruncation();
});
});
} }
}); });
observer.observe(bioTextEl); observer.observe(bioContainerEl);
return () => observer.disconnect(); return () => observer.disconnect();
}); });
@@ -606,9 +614,11 @@
// Recheck truncation after collapsing (wait for DOM update) // Recheck truncation after collapsing (wait for DOM update)
$effect(() => { $effect(() => {
if (bioExpanded === false && bioTextEl) { if (bioExpanded === false && bioTextEl) {
// Use requestAnimationFrame to wait for CSS to apply // Use double RAF to wait for CSS to fully apply
requestAnimationFrame(() => { requestAnimationFrame(() => {
checkBioTruncation(); requestAnimationFrame(() => {
checkBioTruncation();
});
}); });
} }
}); });
@@ -877,7 +887,7 @@
<!-- Biography --> <!-- Biography -->
{#if bioText} {#if bioText}
<div class="biography"> <div class="biography" bind:this={bioContainerEl}>
<div class="bio-text" class:expanded={bioExpanded} bind:this={bioTextEl}> <div class="bio-text" class:expanded={bioExpanded} bind:this={bioTextEl}>
{@html bioText} {@html bioText}
</div> </div>
@@ -1556,7 +1566,7 @@
.artist-header { .artist-header {
display: flex; display: flex;
gap: 32px; gap: 32px;
margin-bottom: 32px; margin-bottom: 22px;
} }
.artist-image-column { .artist-image-column {
@@ -2272,7 +2282,7 @@
/* Top Tracks */ /* Top Tracks */
.top-tracks-section { .top-tracks-section {
padding-top: 10px; margin-top: 32px;
margin-bottom: 32px; margin-bottom: 32px;
} }