From db99ff04cb087809da0bd8758df53dfb38ea16ff Mon Sep 17 00:00:00 2001 From: zurdi Date: Thu, 30 Apr 2026 15:21:30 +0000 Subject: [PATCH] refactor(frontend-v2): optimize background art swapping with dwell timer --- frontend/src/v2/layouts/AppLayout.vue | 61 ++++++++++++--------------- 1 file changed, 28 insertions(+), 33 deletions(-) diff --git a/frontend/src/v2/layouts/AppLayout.vue b/frontend/src/v2/layouts/AppLayout.vue index 0f24ba1d0..4ed031d17 100644 --- a/frontend/src/v2/layouts/AppLayout.vue +++ b/frontend/src/v2/layouts/AppLayout.vue @@ -28,16 +28,32 @@ const layerA = ref(null); const layerB = ref(null); const activeLayer = ref<"a" | "b">("a"); +// Dwell before applying a backdrop swap. Without it, dragging the cursor +// across the gallery would trigger one cross-fade per card and the +// 700ms fades collide as flashes; the latest call wins after the dwell. +const BG_HOVER_DWELL_MS = 80; +let bgTimer: ReturnType | null = null; + function setBackgroundArt(url: string | null) { - if (activeLayer.value === "a") { - if (layerA.value === url) return; - layerB.value = url; - activeLayer.value = "b"; - } else { - if (layerB.value === url) return; - layerA.value = url; - activeLayer.value = "a"; + const current = activeLayer.value === "a" ? layerA.value : layerB.value; + if (current === url) { + if (bgTimer !== null) { + clearTimeout(bgTimer); + bgTimer = null; + } + return; } + if (bgTimer !== null) clearTimeout(bgTimer); + bgTimer = setTimeout(() => { + bgTimer = null; + if (activeLayer.value === "a") { + layerB.value = url; + activeLayer.value = "b"; + } else { + layerA.value = url; + activeLayer.value = "a"; + } + }, BG_HOVER_DWELL_MS); } provide(BACKGROUND_ART_KEY, setBackgroundArt); @@ -60,13 +76,15 @@ onMounted(() => { onBeforeUnmount(() => { removeBackMorph?.(); removeBackMorph = null; + if (bgTimer !== null) { + clearTimeout(bgTimer); + bgTimer = null; + } });