From cd157fc692377642bc370d259bd0c8c287531584 Mon Sep 17 00:00:00 2001 From: Broque Thomas <26755000+Nezreka@users.noreply.github.com> Date: Thu, 16 Apr 2026 15:39:19 -0700 Subject: [PATCH] Fix wishlist button intermittently not navigating to page The active-process check could hang or return stale data, making the button feel unresponsive. Added 2-second timeout with AbortController, fast path for already-visible client process, and graceful fallback to navigateToPage on rehydration failure or timeout. --- webui/static/script.js | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/webui/static/script.js b/webui/static/script.js index cb24c3c6..8339c8e3 100644 --- a/webui/static/script.js +++ b/webui/static/script.js @@ -2820,34 +2820,39 @@ function initializeWatchlist() { watchlistButton.addEventListener('click', () => navigateToPage('watchlist')); } - // Wishlist button: check for active download process first, otherwise navigate to page + // Wishlist button: quick check for active download, otherwise navigate to page const wishlistButton = document.getElementById('wishlist-button'); if (wishlistButton) { wishlistButton.addEventListener('click', async () => { + // Fast path: check if we already know about an active wishlist process + const clientProcess = activeDownloadProcesses['wishlist']; + if (clientProcess && clientProcess.modalElement && document.body.contains(clientProcess.modalElement)) { + clientProcess.modalElement.style.display = 'flex'; + WishlistModalState.setVisible(); + return; + } + // Slow path: ask the server (with timeout to prevent button feeling dead) try { - const resp = await fetch('/api/active-processes'); + const controller = new AbortController(); + const timeout = setTimeout(() => controller.abort(), 2000); + const resp = await fetch('/api/active-processes', { signal: controller.signal }); + clearTimeout(timeout); if (resp.ok) { const data = await resp.json(); const serverProcess = (data.active_processes || []).find(p => p.playlist_id === 'wishlist'); if (serverProcess) { - // Active wishlist download — show the download progress modal - WishlistModalState.clearUserClosed(); - const clientProcess = activeDownloadProcesses['wishlist']; - const needsRehydration = !clientProcess || - clientProcess.batchId !== serverProcess.batch_id || - !clientProcess.modalElement || - !document.body.contains(clientProcess.modalElement); - if (needsRehydration) { + try { + WishlistModalState.clearUserClosed(); await rehydrateModal(serverProcess, true); - } else { - clientProcess.modalElement.style.display = 'flex'; - WishlistModalState.setVisible(); + } catch (e) { + console.debug('Rehydration failed, navigating to page:', e); + navigateToPage('wishlist'); } return; } } } catch (e) { - console.debug('Could not check active processes:', e); + // Timeout or network error — just navigate } navigateToPage('wishlist'); });