mirror of
https://github.com/dergigi/boris.git
synced 2026-01-17 22:04:32 +01:00
fix(reading-position): prevent 0% saves during back navigation
Removed save-on-unmount behavior that was causing 0% position saves when using mobile back gesture. The browser scrolls to top during navigation, triggering a position update to 0% before unmount, which then gets saved. The auto-save with 3-second debounce already captures position during normal reading, so saving on unmount is unnecessary and error-prone. Fixes issue where back gesture on mobile would overwrite reading progress.
This commit is contained in:
@@ -225,7 +225,7 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
||||
}
|
||||
}, [isTextContent, isTrackingEnabled])
|
||||
|
||||
const { progressPercentage, saveNow, suppressSavesFor } = useReadingPosition({
|
||||
const { progressPercentage, suppressSavesFor } = useReadingPosition({
|
||||
enabled: isTrackingEnabled,
|
||||
syncEnabled: settings?.syncReadingPosition !== false,
|
||||
onSave: handleSavePosition,
|
||||
@@ -345,26 +345,10 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
|
||||
}, 500) // Give content time to render
|
||||
}, [isTextContent, activeAccount, articleIdentifier, settings?.syncReadingPosition, selectedUrl, isTrackingEnabled, restoreKey])
|
||||
|
||||
// Save position before unmounting or changing article
|
||||
const saveNowRef = useRef(saveNow)
|
||||
const isTrackingEnabledRef = useRef(isTrackingEnabled)
|
||||
|
||||
useEffect(() => {
|
||||
saveNowRef.current = saveNow
|
||||
}, [saveNow])
|
||||
|
||||
useEffect(() => {
|
||||
isTrackingEnabledRef.current = isTrackingEnabled
|
||||
}, [isTrackingEnabled])
|
||||
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
// Only save on unmount if tracking was actually enabled
|
||||
if (saveNowRef.current && isTrackingEnabledRef.current) {
|
||||
saveNowRef.current()
|
||||
}
|
||||
}
|
||||
}, [selectedUrl])
|
||||
// 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
|
||||
// 3. Position state may not reflect actual reading position during navigation
|
||||
|
||||
// Close menu when clicking outside
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user