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
This commit is contained in:
Gigi
2025-10-22 23:31:47 +02:00
parent c1a23c1f8f
commit b282bc4972

View File

@@ -246,6 +246,12 @@ const ContentPanel: React.FC<ContentPanelProps> = ({
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<ContentPanelProps> = ({
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<ContentPanelProps> = ({
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)
}