mirror of
https://github.com/dergigi/boris.git
synced 2026-01-17 13:54:24 +01:00
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.
This commit is contained in:
@@ -331,7 +331,7 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
||||
|
||||
// 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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user