Skip to content

UX: Restoring the scroll state on back navigation is broken #5211

Closed

Description

@AlynxZhou

1. What is not working as documented?

In web browser, if I scroll down some steps (as the page will load more when scrolled to bottom, you have to make it load) and open a folder in folders view, then click back to return to folders view, it will try to restore to previous position, but it won't automatically load more folders when reaching bottom, so the position is not correct. You always stop at initial loaded folders, which makes it hard to use if you are trying finding some old photos, you have to manually scroll to trigger auto loading to reach previous position.

2. How can we reproduce it?

Steps to reproduce the behavior:

  1. Go to 'folders' view
  2. Scroll down to bottom to trigger auto loading more folders
  3. Click a folder that is loaded with auto loading, not a initial loaded folder
  4. Click back button of browser
  5. It will try to restore previous scroll position, but it won't trigger auto loading when reaches bottom, so it always stops at initial loaded folders.

3. What behavior do you expect?

It saves previously loaded folders and restore to the position correctly, or while restoring the position it automatically triggers reloading and restore the position correctly.

4. What could be the cause of your problem?

I can see it did 1 auto loading when reached to bottom on restoring position, but then it stops to restoring position, maybe we need some way to continue loading and scrolling until reaches the correct position.

5. Can you provide us with example files for testing, error logs, or screenshots?

6. Which software versions do you use?

(a) PhotoPrism Architecture & Build Number: 250707-d28b3101e-Linux-x86_64

(b) Database Type & Version: mariadb from 12.0.2-MariaDB, client 15.2 for Linux (x86_64) using readline 5.1

(c) Operating System Types & Versions: Arch Linux 6.16.4-arch1-1

(d) Browser Types & Versions: Both Firefox and Chrome on macOS can reproduce this.

(e) Ad Blockers, Browser Plugins, and/or Firewall Software? This can be reproduced in Private window.

7. On what kind of device is PhotoPrism installed?

This is especially important if you are reporting a performance, import, or indexing issue. You can skip this if you're reporting a problem you found in our public demo, or if it's a completely unrelated issue, such as incorrect page layout.

(a) Device / Processor Type: Ryzen 3 PRO 5350G

(b) Physical Memory & Swap Space in GB: 32GB/32GB

(c) Storage Type: HDD, SSD, RAID, USB, Network Storage,...: 4-HDD RAID10

(d) Anything else that might be helpful to know? None

8. Do you use a Reverse Proxy, Firewall, VPN, or CDN?

No, I reproduced this in my home and I directly connected to PhotoPrism's HTTP port.

Activity

  1. graciousgrey commented on Sep 15, 2025

    @graciousgrey
    Member

    Thanks for the report and the clear reproduction hints!

    What’s happening
    – The scroll position is remembered and a restore is triggered when you navigate back.
    – However, the restore callback currently fires only once right after mount. At that moment, the album/folder item near the bottom often isn’t in the DOM yet because the list is still loading in batches (infinite scroll). As a result, the browser can’t scroll to a target that hasn’t been rendered, so you end up at the top again.

    Why this is expected with our current loading strategy
    – Albums and Folders views use progressive loading with virtualization / placeholders to keep memory and rendering costs under control. See Developer Guide
    – On back-navigation we do restore, but we don’t retry once more items arrive, so the first (and only) attempt can miss when the target item is far down the list.

    Two ways forward (trade-offs)

    1. “Wait longer” approach
      – Delay the single restore callback in hopes that enough items have loaded.
      – Doesn’t reliably fix slow connections or very large lists; still races.

    2. “Load enough & retry” approach (recommended)
      – Persist both the last clicked item’s UID and its index (position) when navigating into an item.
      – On return:
      a) Increase the initial batch so the saved index is included, e.g. request count = max(default, savedIndex + smallBuffer).
      b) Re-attempt restore whenever a batch finishes until either:
      • the saved index is loaded (then scroll to the item/approximate offset), or
      • a sane cap is reached.
      – Because our API supports count/offset, we can request a larger first page or jump via offset when needed
      – With pseudo-virtualization in place, fetching metadata models for N items is cheap; thumbs render only when visible.

    Implementation sketch
    – Persist on click:
    history.state = { uid, index, scrollY }
    – On the Albums/Folders page
    • Read saved { uid, index } on mounted.
    • Compute initialCount = Math.max(defaultCount, index + buffer).
    • Trigger first load with initialCount (or offset/index-aware query).
    • After each “batch appended” event, call tryRestore():

    if (!restored && loadedCount > index) {
            // Option A: precise
            scrollToElementByUid(uid);
            restored = true;
          } else if (!restored && indexKnown) {
            // Option B: approximate early jump; refine once the target renders
            container.scrollTop = estimatedTileHeight * index;
          }
    

    • Stop retrying once restored or a hard limit is reached.

    Notes / limits
    – “Load all” in one go is risky (time/memory) on very large libraries; better to load “enough” based on index plus a small buffer, then retry restore as batches arrive.
    – We should also reset any accumulated back-navigation offset after a successful restore (see #2627) to avoid growing first-load sizes across sessions.

    If there are no objections, we’ll proceed with option (2): save UID+index on navigation, increase the initial batch size based on index, and retry scrolling after each appended batch until the target exists. This should make back-navigation deterministic even when the destination is far down the list and the connection is slow.

    Links for context

  2. moved this to Upcoming ⏳ in Roadmap 🚀✨on Sep 15, 2025
  3. self-assigned this
    on Oct 3, 2025
  4. moved this from Upcoming ⏳ to Development 🐝 in Roadmap 🚀✨on Oct 3, 2025
  5. added theissue type on Oct 3, 2025
  6. lastzero commented on Oct 3, 2025

    @lastzero
    Member

    @AlynxZhou These changes should resolve the issue. Let us know if it works!

    I'll start a new preview build soon so you can test it:

  7. 23 remaining items

  8. AlynxZhou commented on Oct 9, 2025

    @AlynxZhou
    Author

    I changed both view.js and notify.js, still not work, it loads once more but not scrolling down.

  9. lastzero commented on Oct 9, 2025

    @lastzero
    Member

    It turned out that the way the back navigation was detected didn't work with the current browsers and Vue version anymore, so I introduced a new, more advanced detection method in our view helper. You are welcome to test it and provide feedback!

  10. added
    please-testReady for manual testing & feedback
    and removed
    needs-analysisRequires further investigation
    on Oct 9, 2025
  11. moved this from Development 🐝 to Preview 🐳 in Roadmap 🚀✨on Oct 9, 2025
  12. changed the title [-]UX: Restore scroll position with auto loaded more folders when back from folder to all folders[/-] [+]UX: Restoring the scroll state on back navigation is broken[/+] on Oct 9, 2025
  13. AlynxZhou commented on Oct 10, 2025

    @AlynxZhou
    Author

    This times it works as intended. We could close this and I am waiting for the next stable release.

  14. AlynxZhou commented on Oct 10, 2025

    @AlynxZhou
    Author

    I am very appreciate for your work!

  15. added
    testedChanges have been tested successfully
    and removed
    please-testReady for manual testing & feedback
    on Oct 11, 2025
  16. moved this from Preview 🐳 to Release 🌈 in Roadmap 🚀✨on Dec 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

frontendRequires experience with HTML/JS/CSStestedChanges have been tested successfullyuxImpacts User Experience

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions