From abd132951f8195c987ae44ab4ab8cfe62a2f8ca4 Mon Sep 17 00:00:00 2001 From: "shakespeare.diy" Date: Mon, 13 Oct 2025 20:12:27 -0500 Subject: [PATCH] Fix app shuffle on typing in new project view The AppShowcase component was re-shuffling apps on every render because useMemo dependencies were unstable (filtered arrays created new references on each render). Fixed by consolidating all filtering and shuffling logic into a single useMemo with only the submissions array as a dependency. This ensures apps only shuffle when submissions data actually changes, not when user types in the text box. Changes: - Moved all filtering logic into single useMemo block - Changed dependency from intermediate filtered arrays to just submissions - Apps now maintain stable order while user types --- src/components/AppShowcase.tsx | 52 ++++++++++++++++------------------ 1 file changed, 25 insertions(+), 27 deletions(-) diff --git a/src/components/AppShowcase.tsx b/src/components/AppShowcase.tsx index 8cf9ad9f..f8f628e7 100644 --- a/src/components/AppShowcase.tsx +++ b/src/components/AppShowcase.tsx @@ -32,38 +32,36 @@ export function AppShowcase() { }, [config.showcaseModerator]); const isModerator = user?.pubkey === MODERATOR_HEX; - // Filter submissions - const visibleSubmissions = submissions.filter(app => !app.isHidden); + // Filter and shuffle submissions - memoized with stable dependency + const { templateApps, halloweenApps, featuredApps, approvedApps } = useMemo(() => { + // Filter visible submissions + const visibleSubmissions = submissions.filter(app => !app.isHidden); - // Separate template apps from other apps - const templateApps = useMemo(() => - shuffleArray(visibleSubmissions.filter(app => app.appTags.includes('Template'))), - [visibleSubmissions] - ); - const nonTemplateSubmissions = visibleSubmissions.filter(app => !app.appTags.includes('Template')); + // Separate template apps from other apps + const templates = shuffleArray(visibleSubmissions.filter(app => app.appTags.includes('Template'))); + const nonTemplateSubmissions = visibleSubmissions.filter(app => !app.appTags.includes('Template')); - // Get Halloween Hackathon 2025 apps that are featured (for main showcase) - const halloweenApps = useMemo(() => - shuffleArray(nonTemplateSubmissions.filter(app => + // Get Halloween Hackathon 2025 apps that are featured (for main showcase) + const halloween = shuffleArray(nonTemplateSubmissions.filter(app => app.appTags.includes('Halloween Hackathon 2025') && app.isFeatured - )), - [nonTemplateSubmissions] - ); + )); - // Filter out Halloween Hackathon 2025 apps from other sections (unless featured, they go in Halloween section) - const nonHalloweenSubmissions = nonTemplateSubmissions.filter(app => - !app.appTags.includes('Halloween Hackathon 2025') - ); + // Filter out Halloween Hackathon 2025 apps from other sections (unless featured, they go in Halloween section) + const nonHalloweenSubmissions = nonTemplateSubmissions.filter(app => + !app.appTags.includes('Halloween Hackathon 2025') + ); - // Shuffle featured and approved apps on each component mount/render for random display order - const featuredApps = useMemo(() => - shuffleArray(nonHalloweenSubmissions.filter(app => app.isFeatured)), - [nonHalloweenSubmissions] - ); - const approvedApps = useMemo(() => - shuffleArray(nonHalloweenSubmissions.filter(app => app.isApproved && !app.isFeatured)), - [nonHalloweenSubmissions] - ); + // Shuffle featured and approved apps for random display order + const featured = shuffleArray(nonHalloweenSubmissions.filter(app => app.isFeatured)); + const approved = shuffleArray(nonHalloweenSubmissions.filter(app => app.isApproved && !app.isFeatured)); + + return { + templateApps: templates, + halloweenApps: halloween, + featuredApps: featured, + approvedApps: approved, + }; + }, [submissions]); // Only depend on submissions, not intermediate filtered arrays // Don't show showcase if disabled in settings if (!config.showcaseEnabled) {