fix(reading): prevent saveNow from firing on every position change

The unmount effect had saveNow in its dependency array. Since saveNow is a useCallback that depends on position, it was recreated on every scroll event, triggering the effect cleanup and calling saveNow() repeatedly (every ~14ms).

Now using a ref to store the latest saveNow callback, so the cleanup only runs when selectedUrl changes (i.e., when actually navigating away).
This commit is contained in:
Gigi
2025-10-22 23:22:16 +02:00
parent 90f25420b2
commit 496bbc36f4

View File

@@ -295,13 +295,18 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
}, [isTextContent, activeAccount, relayPool, eventStore, articleIdentifier, settings?.syncReadingPosition, selectedUrl, suppressSavesFor])
// Save position before unmounting or changing article
const saveNowRef = useRef(saveNow)
useEffect(() => {
saveNowRef.current = saveNow
}, [saveNow])
useEffect(() => {
return () => {
if (saveNow) {
saveNow()
if (saveNowRef.current) {
saveNowRef.current()
}
}
}, [saveNow, selectedUrl])
}, [selectedUrl])
// Close menu when clicking outside
useEffect(() => {