diff --git a/public/app.js b/public/app.js index fb5e607..75a38ec 100644 --- a/public/app.js +++ b/public/app.js @@ -99,7 +99,15 @@ function dismissSplash(startTime) { setTimeout(() => { const splash = document.getElementById('splash-screen'); splash.classList.add('fade-out'); + // Fallback: resolve after transition duration + buffer in case + // transitionend never fires (e.g. display was toggled in same frame) + const TRANSITION_MS = 400; + const fallback = setTimeout(() => { + splash.style.display = 'none'; + resolve(); + }, TRANSITION_MS + 100); splash.addEventListener('transitionend', () => { + clearTimeout(fallback); splash.style.display = 'none'; resolve(); }, { once: true }); @@ -152,9 +160,13 @@ async function handleLogin(e) { if (data.success) { currentUser = data.user; isAdmin = !!data.user.isAdmin; - // Fade out login, then show splash while loading data + // Fade out login, then show splash while loading data. + // requestAnimationFrame ensures the browser paints the splash at + // opacity:1 before dismissSplash adds fade-out, so the CSS + // transition fires and transitionend is guaranteed. await fadeOutLogin(); showSplash(); + await new Promise(r => requestAnimationFrame(() => requestAnimationFrame(r))); showDashboard(); const splashStart = Date.now(); await fetchUserDownloads(true);