From 5d4d11512d8f915e3684a5483985a4a3f99aef09 Mon Sep 17 00:00:00 2001 From: Garret Patti <42485635+garretpatti@users.noreply.github.com> Date: Fri, 10 Apr 2026 21:13:06 -0400 Subject: [PATCH] Fix DoomScrollView going blank after 100 items MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When history hit the 100-entry cap, setHistory sliced the array back to indices 0–99 but setHistoryIndex still returned idx + 1 = 100, making current = history[100] = undefined. Nothing rendered and no API calls were made until the user went back (decrementing to index 99, which held the newly-picked item). Fix: cap the returned historyIndex at HISTORY_CAP - 1 so it always points to a valid entry in the sliced array. Extract HISTORY_CAP = 100 as a named constant so the slice and the index cap stay in sync. Co-Authored-By: Claude Sonnet 4.6 --- src/components/DoomScrollView.tsx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/components/DoomScrollView.tsx b/src/components/DoomScrollView.tsx index af00d73..4de737d 100644 --- a/src/components/DoomScrollView.tsx +++ b/src/components/DoomScrollView.tsx @@ -16,6 +16,8 @@ interface Props { onClose: () => void } +const HISTORY_CAP = 100 + function pickRandom(items: DoomScrollItem[], excludeRecent: DoomScrollItem[]): DoomScrollItem { const excludeCount = Math.min(excludeRecent.length, items.length - 1) const recentUrls = new Set(excludeRecent.slice(-excludeCount).map((i) => i.url)) @@ -55,9 +57,9 @@ export default function DoomScrollView({ items, videoContext = 'mixed', onClose const next = pickRandom(items, history) setHistory((h) => { const updated = [...h, next] - return updated.length > 100 ? updated.slice(-100) : updated + return updated.length > HISTORY_CAP ? updated.slice(-HISTORY_CAP) : updated }) - return idx + 1 + return Math.min(idx + 1, HISTORY_CAP - 1) }) }, [items, history])