From 39aaa4a465f43cb65f8e3c3612c08e7c462c6465 Mon Sep 17 00:00:00 2001 From: Stefan Hardegger Date: Mon, 23 Feb 2026 11:31:36 +0100 Subject: [PATCH] fix scrolling to position. --- frontend/src/app/stories/[id]/page.tsx | 8 ++++++-- .../src/components/collections/CollectionReadingView.tsx | 8 ++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/frontend/src/app/stories/[id]/page.tsx b/frontend/src/app/stories/[id]/page.tsx index 6b01530..b7c2146 100644 --- a/frontend/src/app/stories/[id]/page.tsx +++ b/frontend/src/app/stories/[id]/page.tsx @@ -140,10 +140,14 @@ export default function StoryReadingPage() { // Calculate target scroll position const targetScroll = contentTop + (ratio * contentHeight) - (windowHeight * 0.3); - // Smooth scroll to position + // Use smooth scrolling only for shorter stories (< 15 000 words). + // For longer stories the saved position can be 50 000+ px from the top; + // browsers animate smooth-scroll at ~1 000–1 500 px/s, so the animation + // would take tens of seconds and often stalls or cancels before finishing. + const scrollBehavior = (story.wordCount ?? 0) < 15000 ? 'smooth' : 'instant'; window.scrollTo({ top: Math.max(0, targetScroll), - behavior: 'smooth' + behavior: scrollBehavior }); setHasScrolledToPosition(true); diff --git a/frontend/src/components/collections/CollectionReadingView.tsx b/frontend/src/components/collections/CollectionReadingView.tsx index c3c0de7..24b524b 100644 --- a/frontend/src/components/collections/CollectionReadingView.tsx +++ b/frontend/src/components/collections/CollectionReadingView.tsx @@ -70,10 +70,14 @@ export default function CollectionReadingView({ // Calculate target scroll position const targetScroll = contentTop + (ratio * contentHeight) - (windowHeight * 0.3); - // Smooth scroll to position + // Use smooth scrolling only for shorter stories (< 15 000 words). + // For longer stories the saved position can be 50 000+ px from the top; + // browsers animate smooth-scroll at ~1 000–1 500 px/s, so the animation + // would take tens of seconds and often stalls or cancels before finishing. + const scrollBehavior = (story.wordCount ?? 0) < 15000 ? 'smooth' : 'instant'; window.scrollTo({ top: Math.max(0, targetScroll), - behavior: 'smooth' + behavior: scrollBehavior }); setHasScrolledToPosition(true);