Kaynağa Gözat

fix(ui): reset scroll position when marking a page as read

Replace `window.location.reload()` with `window.location.replace()` in
`markPageAsReadAction()` and `goToPage()` so marking a page as read
loads the next page at the top instead of restoring the previous scroll
position (regression from bbe3c2ea).

Fixes #3743
moppman 2 gün önce
ebeveyn
işleme
249d308508
1 değiştirilmiş dosya ile 15 ekleme ve 2 silme
  1. 15 2
      internal/ui/static/js/app.js

+ 15 - 2
internal/ui/static/js/app.js

@@ -275,6 +275,19 @@ function showToastNotification(iconType, notificationMessage) {
     setTimeout(() => toastElementWrapper.classList.add("toast-animate"), 100);
 }
 
+/**
+ * Navigate to the current page from the top without preserving scroll position.
+ *
+ * Unlike location.reload(), location.replace() does not restore the previous
+ * scroll position. We also clear the hash so the browser fetches the page
+ * instead of treating location.replace() as an in-page jump.
+ */
+function reloadPageAtTop() {
+    const url = new URL(window.location.href);
+    url.hash = "";
+    window.location.replace(url.href);
+}
+
 /**
  * Navigate to a specific page.
  *
@@ -287,7 +300,7 @@ function goToPage(page, reloadOnFail = false) {
     if (element) {
         document.location.href = element.href;
     } else if (reloadOnFail) {
-        window.location.reload();
+        reloadPageAtTop();
     }
 }
 
@@ -588,7 +601,7 @@ function markPageAsReadAction() {
         const showOnlyUnread = element?.dataset.showOnlyUnread || false;
 
         if (showOnlyUnread) {
-            window.location.reload();
+            reloadPageAtTop();
         } else {
             goToPage("next", true);
         }