From 64de02eef13b302049628402326ac6a943ba1249 Mon Sep 17 00:00:00 2001 From: sametbasbug Date: Sun, 2 Aug 2026 08:13:30 +0300 Subject: [PATCH] Stabilize pagination scroll restoration --- src/components/Pagination.astro | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/components/Pagination.astro b/src/components/Pagination.astro index 7420f83..bf56807 100644 --- a/src/components/Pagination.astro +++ b/src/components/Pagination.astro @@ -46,7 +46,20 @@ const olderPage = currentPage < totalPages ? currentPage + 1 : undefined; }); if (sessionStorage.getItem(scrollKey) === 'true') { + const previousScrollRestoration = history.scrollRestoration; + const scrollToTop = () => window.scrollTo({ top: 0, left: 0, behavior: 'auto' }); + sessionStorage.removeItem(scrollKey); - requestAnimationFrame(() => window.scrollTo({ top: 0, left: 0, behavior: 'instant' })); + history.scrollRestoration = 'manual'; + scrollToTop(); + requestAnimationFrame(scrollToTop); + + window.addEventListener('pageshow', () => { + scrollToTop(); + requestAnimationFrame(() => { + scrollToTop(); + history.scrollRestoration = previousScrollRestoration; + }); + }, { once: true }); }