From b1ce977dcd81776c980f07db87d8fa1cdb1f5377 Mon Sep 17 00:00:00 2001 From: schroda <50052685+schroda@users.noreply.github.com> Date: Mon, 1 Apr 2024 13:17:50 +0200 Subject: [PATCH] Wait for initial page to be rendered before scrolling it into view (#696) The ResizeObserver triggers the first time when the element has a height of 0, which apparently did not work with scrolling it into view. Due to immediately disconnecting the observer, the next resize event, which would successfully scroll the page into view, was never handled Regression introduced with 0c1abebaf47b0cd92c0f32cad316e867e96e322c --- src/components/reader/pager/HorizontalPager.tsx | 4 ++++ src/components/reader/pager/VerticalPager.tsx | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/components/reader/pager/HorizontalPager.tsx b/src/components/reader/pager/HorizontalPager.tsx index 0eb9731e..79d60dca 100644 --- a/src/components/reader/pager/HorizontalPager.tsx +++ b/src/components/reader/pager/HorizontalPager.tsx @@ -114,6 +114,10 @@ export function HorizontalPager(props: IReaderProps) { } const resizeObserver = new ResizeObserver(() => { + if (!initialPageElement.offsetHeight) { + return; + } + initialPageElement.scrollIntoView({ inline: 'center' }); resizeObserver.disconnect(); }); diff --git a/src/components/reader/pager/VerticalPager.tsx b/src/components/reader/pager/VerticalPager.tsx index 6ee1155e..d363afc6 100644 --- a/src/components/reader/pager/VerticalPager.tsx +++ b/src/components/reader/pager/VerticalPager.tsx @@ -172,6 +172,10 @@ export function VerticalPager(props: IReaderProps) { } const resizeObserver = new ResizeObserver(() => { + if (!initialPageElement.offsetHeight) { + return; + } + initialPageElement.scrollIntoView(); resizeObserver.disconnect(); });