From b282bc4972b2e42f9e65e31de37caa590f6a7e21 Mon Sep 17 00:00:00 2001 From: Gigi Date: Wed, 22 Oct 2025 23:31:47 +0200 Subject: [PATCH] fix(reading): suppress saves during restore to prevent overwriting - Suppress saves for 1700ms when restore starts (covers collection + render time) - If no position found or delta too small, clear suppression immediately - If restore happens, extend suppression for 1.5s after scroll - Prevents 0% from overwriting saved 22% position during page load --- src/components/ContentPanel.tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/components/ContentPanel.tsx b/src/components/ContentPanel.tsx index 56510af6..0a8463a0 100644 --- a/src/components/ContentPanel.tsx +++ b/src/components/ContentPanel.tsx @@ -246,6 +246,12 @@ const ContentPanel: React.FC = ({ console.log('[reading-position] 🔄 Initiating restore for article:', articleIdentifier) hasAttemptedRestoreRef.current = articleIdentifier + + // Suppress saves during restore window (700ms collection + 500ms render + 500ms buffer = 1700ms) + if (suppressSavesForRef.current) { + suppressSavesForRef.current(1700) + } + const collector = collectReadingPositionsOnce({ relayPool, eventStore, @@ -257,6 +263,10 @@ const ContentPanel: React.FC = ({ collector.onStable((bestPosition) => { if (!bestPosition) { console.log('[reading-position] â„šī¸ No position to restore') + // No saved position, allow saves immediately + if (suppressSavesForRef.current) { + suppressSavesForRef.current(0) + } return } @@ -284,12 +294,16 @@ const ContentPanel: React.FC = ({ const deltaPct = maxScroll > 0 ? Math.abs((targetTop - currentTop) / maxScroll) : 0 if (deltaPx < 48 || deltaPct < 0.05) { console.log('[reading-position] â­ī¸ Restore skipped: delta too small (', deltaPx, 'px,', Math.round(deltaPct * 100) + '%)') + // Allow saves immediately since no scroll happened + if (suppressSavesForRef.current) { + suppressSavesForRef.current(0) + } return } console.log('[reading-position] 📜 Restoring scroll position (delta:', deltaPx, 'px,', Math.round(deltaPct * 100) + '%)') - // Suppress saves briefly to avoid feedback loop + // Suppress saves for another 1.5s after scroll to avoid saving the restored position if (suppressSavesForRef.current) { suppressSavesForRef.current(1500) }