fix(reading): prevent restore effect from restarting during content load

Track whether we've already attempted restore for each article using a ref. Prevents the effect from restarting multiple times as html/markdown/loading state changes during initial page load, which was stopping the stabilization timer before it could complete.
This commit is contained in:
Gigi
2025-10-22 23:29:29 +02:00
parent 8a5aacfe7b
commit c1a23c1f8f

View File

@@ -225,6 +225,9 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
suppressSavesForRef.current = suppressSavesFor
}, [suppressSavesFor])
// Track if we've already attempted restore for this article
const hasAttemptedRestoreRef = useRef<string | null>(null)
useEffect(() => {
if (!isTextContent || !activeAccount || !relayPool || !eventStore || !articleIdentifier) {
console.log('[reading-position] ⏭️ Restore skipped: missing dependencies or not text content')
@@ -235,7 +238,14 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
return
}
// Only attempt restore once per article
if (hasAttemptedRestoreRef.current === articleIdentifier) {
console.log('[reading-position] ⏭️ Restore skipped: already attempted for this article')
return
}
console.log('[reading-position] 🔄 Initiating restore for article:', articleIdentifier)
hasAttemptedRestoreRef.current = articleIdentifier
const collector = collectReadingPositionsOnce({
relayPool,
eventStore,