From fca3917a12d3cc5e7df8aacc81380aeda07fd87b Mon Sep 17 00:00:00 2001 From: Huang Xin Date: Mon, 2 Feb 2026 21:28:11 +0800 Subject: [PATCH] fix(toc): prevent unintentional scrolling in the TOC, closes #3124 (#3144) --- .../app/reader/components/sidebar/TOCView.tsx | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/apps/readest-app/src/app/reader/components/sidebar/TOCView.tsx b/apps/readest-app/src/app/reader/components/sidebar/TOCView.tsx index ed517d62..34ace669 100644 --- a/apps/readest-app/src/app/reader/components/sidebar/TOCView.tsx +++ b/apps/readest-app/src/app/reader/components/sidebar/TOCView.tsx @@ -77,20 +77,12 @@ const TOCView: React.FC<{ const isInCooldown = useCallback(() => { if (!hasInteractedWithTOCRef.current) return false; - const now = Date.now(); - const timeSinceInteraction = now - lastInteractionTimeRef.current; - if (timeSinceInteraction >= interactionCooldownMs) { - hasInteractedWithTOCRef.current = false; - return false; - } - return true; + return Date.now() - lastInteractionTimeRef.current < interactionCooldownMs; }, []); const handleInteraction = useCallback(() => { - setTimeout(() => { - hasInteractedWithTOCRef.current = true; - lastInteractionTimeRef.current = Date.now(); - }, 500); + hasInteractedWithTOCRef.current = true; + lastInteractionTimeRef.current = Date.now(); }, []); useEffect(() => { @@ -252,6 +244,7 @@ const TOCView: React.FC<{ if (!isSideBarVisible) return; if (sideBarBookKey !== bookKey) return; if (isInCooldown()) return; + hasInteractedWithTOCRef.current = false; const { sectionHref: currentHref } = progress; if (currentHref) { @@ -261,6 +254,7 @@ const TOCView: React.FC<{ useEffect(() => { if (isInCooldown()) return; + hasInteractedWithTOCRef.current = false; if (flatItems.length > 0) { setTimeout(scrollToActiveItem, appService?.isAndroidApp ? 300 : 100); @@ -268,7 +262,9 @@ const TOCView: React.FC<{ // eslint-disable-next-line react-hooks/exhaustive-deps }, [progress, scrollToActiveItem, isInCooldown]); - return sections && sections.length > 256 ? ( + const useVirtualization = sections && sections.length > 256; + + return useVirtualization ? (