From ca32dfca5103f9f42d97cbac6844ea7271637c6d Mon Sep 17 00:00:00 2001 From: Gigi Date: Thu, 23 Oct 2025 01:04:54 +0200 Subject: [PATCH] perf: reduce reading position throttle from 3s to 1s Reading position now saves every 1 second during continuous scrolling instead of every 3 seconds, providing more frequent position updates. --- src/components/ContentPanel.tsx | 2 +- src/hooks/useReadingPosition.ts | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/components/ContentPanel.tsx b/src/components/ContentPanel.tsx index 94f1cd45..4bca4d43 100644 --- a/src/components/ContentPanel.tsx +++ b/src/components/ContentPanel.tsx @@ -331,7 +331,7 @@ const ContentPanel: React.FC = ({ // Note: We intentionally do NOT save on unmount because: // 1. Browser may scroll to top during back navigation, causing 0% saves - // 2. The auto-save with 3s debounce already captures position during reading + // 2. The auto-save with 1s throttle already captures position during reading // 3. Position state may not reflect actual reading position during navigation // Close menu when clicking outside diff --git a/src/hooks/useReadingPosition.ts b/src/hooks/useReadingPosition.ts index 5ee38690..c8571dc0 100644 --- a/src/hooks/useReadingPosition.ts +++ b/src/hooks/useReadingPosition.ts @@ -35,7 +35,7 @@ export const useReadingPosition = ({ suppressUntilRef.current = until }, []) - // Throttled save function - saves at 3s intervals during scrolling + // Throttled save function - saves at 1s intervals during scrolling const scheduleSave = useCallback((currentPosition: number) => { if (!syncEnabled || !onSave) { return @@ -56,12 +56,12 @@ export const useReadingPosition = ({ pendingPositionRef.current = currentPosition // Throttle: only schedule a save if one isn't already pending - // This ensures saves happen at regular 3s intervals during continuous scrolling + // This ensures saves happen at regular 1s intervals during continuous scrolling if (saveTimerRef.current) { return // Already have a save scheduled, don't reset the timer } - const THROTTLE_MS = 3000 + const THROTTLE_MS = 1000 saveTimerRef.current = setTimeout(() => { // Save the latest position, not the one from when timer was scheduled const positionToSave = pendingPositionRef.current