From 7bc4522be435e5746ae5f6930f90f52abbf2d16f Mon Sep 17 00:00:00 2001 From: Gigi Date: Wed, 22 Oct 2025 23:35:55 +0200 Subject: [PATCH] fix(reading): prevent false 100% detection during page transitions Add guards to prevent detecting 100% completion when: - Document height is < 100px (likely during transition) - scrollTop is < 100px (not actually scrolled) Prevents accidentally saving 100% when navigating away at 50%. --- src/hooks/useReadingPosition.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/hooks/useReadingPosition.ts b/src/hooks/useReadingPosition.ts index 7b77bcd4..b9f6ea7b 100644 --- a/src/hooks/useReadingPosition.ts +++ b/src/hooks/useReadingPosition.ts @@ -116,13 +116,16 @@ export const useReadingPosition = ({ const windowHeight = window.innerHeight const documentHeight = document.documentElement.scrollHeight + // Ignore if document is too small (likely during page transition) + if (documentHeight < 100) return + // Calculate position based on how much of the content has been scrolled through - // Add a small threshold (5px) to account for rounding and make it easier to reach 100% const maxScroll = documentHeight - windowHeight const scrollProgress = maxScroll > 0 ? scrollTop / maxScroll : 0 - // If we're within 5px of the bottom, consider it 100% - const isAtBottom = scrollTop + windowHeight >= documentHeight - 5 + // Only consider it 100% if we're truly at the bottom AND have scrolled significantly + // This prevents false 100% during page transitions + const isAtBottom = scrollTop + windowHeight >= documentHeight - 5 && scrollTop > 100 const clampedProgress = isAtBottom ? 1 : Math.max(0, Math.min(1, scrollProgress)) setPosition(clampedProgress)