From 9268a4635f25d9680be65a19a926969d637933cd Mon Sep 17 00:00:00 2001 From: Geert Rademakes Date: Wed, 6 Aug 2025 10:47:37 +0200 Subject: [PATCH] perf: Remove unnecessary delays in playlist switching and infinite scroll - Remove setTimeout delay in playlist change handler - Reduce infinite scroll trigger delay from 1000ms to 100ms - Improve responsiveness when switching playlists and scrolling - Fixes 1-second delay between URL change and actual loading --- packages/frontend/src/components/PaginatedSongList.tsx | 2 +- packages/frontend/src/hooks/usePaginatedSongs.ts | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/packages/frontend/src/components/PaginatedSongList.tsx b/packages/frontend/src/components/PaginatedSongList.tsx index 1430296..8b9b143 100644 --- a/packages/frontend/src/components/PaginatedSongList.tsx +++ b/packages/frontend/src/components/PaginatedSongList.tsx @@ -257,7 +257,7 @@ export const PaginatedSongList: React.FC = memo(({ // Reset the flag after a short delay to prevent multiple triggers timeoutRef.current = setTimeout(() => { isTriggeringRef.current = false; - }, 1000); + }, 100); } }, { diff --git a/packages/frontend/src/hooks/usePaginatedSongs.ts b/packages/frontend/src/hooks/usePaginatedSongs.ts index 93fad38..6fdcee6 100644 --- a/packages/frontend/src/hooks/usePaginatedSongs.ts +++ b/packages/frontend/src/hooks/usePaginatedSongs.ts @@ -149,10 +149,8 @@ export const usePaginatedSongs = (options: UsePaginatedSongsOptions = {}) => { setCurrentPage(1); setSearchQuery(initialSearch); setError(null); - // Use setTimeout to avoid the dependency issue - setTimeout(() => { - loadPage(1, initialSearch, playlistName); - }, 0); + // Load immediately without setTimeout + loadPage(1, initialSearch, playlistName); } }, [playlistName, isInitialLoad, initialSearch, loadPage]);