diff --git a/components/StudyFeed.tsx b/components/StudyFeed.tsx index d0970c8..55c38b6 100644 --- a/components/StudyFeed.tsx +++ b/components/StudyFeed.tsx @@ -24,6 +24,8 @@ export function StudyFeed({ deck }: { deck: Deck }) { const [streak, setStreak] = useState(0); const [bestStreak, setBestStreak] = useState(0); const [retryMode, setRetryMode] = useState(false); + /** Bumped on every restart so the activity components remount fresh. */ + const [runId, setRunId] = useState(0); const scrollRef = useRef(null); const recordedRef = useRef(false); @@ -134,12 +136,19 @@ export function StudyFeed({ deck }: { deck: Deck }) { setStreak(0); setRetryMode(retry); recordedRef.current = retry; // don't overwrite the best score with a retry run + // A new run: remount every activity (fresh state) and jump to the top. + setRunId((value) => value + 1); setIndex(0); - requestAnimationFrame(() => goTo(0)); }, - [goTo], + [], ); + // Whenever a run starts (including the first render), snap back to slide 1. + useEffect(() => { + const container = scrollRef.current; + if (container) container.scrollTop = 0; + }, [runId]); + const progressValue = Math.min(index + 1, slideCount); const progressMax = slideCount; @@ -205,7 +214,7 @@ export function StudyFeed({ deck }: { deck: Deck }) { > {queue.map((activity, activityIndex) => (