fix(reading): reset restore attempt tracker when article changes

Previously, if restore was skipped due to missing dependencies (content not loaded), it would never retry even after content loaded. Now resets the attempt tracker whenever articleIdentifier changes, allowing retry when dependencies become available.
This commit is contained in:
Gigi
2025-10-22 23:49:07 +02:00
parent 3b22cb5c5d
commit ffa4b38106

View File

@@ -244,8 +244,13 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
suppressSavesForRef.current = suppressSavesFor
}, [suppressSavesFor])
// Track if we've already attempted restore for this article
// Track if we've successfully started restore for this article
const hasAttemptedRestoreRef = useRef<string | null>(null)
// Reset attempt tracker when article changes
useEffect(() => {
hasAttemptedRestoreRef.current = null
}, [articleIdentifier])
useEffect(() => {
if (!isTextContent || !activeAccount || !relayPool || !eventStore || !articleIdentifier) {
@@ -257,13 +262,14 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
return
}
// Only attempt restore once per article
// Only attempt restore once per article (after dependencies are ready)
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)
// Mark as attempted ONLY after all checks pass
hasAttemptedRestoreRef.current = articleIdentifier
// Suppress saves during restore window (700ms collection + 500ms render + 500ms buffer = 1700ms)