Skip to content

Fix scroll position not being preserved when pages load slowly#7143

Merged
Chocobozzz merged 2 commits into
Chocobozzz:developfrom
bojidar-bg:7097-back-history-scroll
Jul 9, 2025
Merged

Fix scroll position not being preserved when pages load slowly#7143
Chocobozzz merged 2 commits into
Chocobozzz:developfrom
bojidar-bg:7097-back-history-scroll

Conversation

@bojidar-bg

@bojidar-bg bojidar-bg commented Jul 7, 2025

Copy link
Copy Markdown
Contributor

Description

Before this change, ScrollService attempted to scroll down immediately after navigating, before before the page had fully loaded.
I considered making the Table component (and other data-loading componets) responsible for telling the ScrollService that data has been loaded—or to use Angular's Route.resolve property, but realized that using ResizeObserver to get the page size is a lot more reliable (and a small code change overall, so less painful 😁).

I'm pretty sure there is some way to use RxJS observables for the unhandledScrollEvent variable I added, but I couldn't figure out a good way to do so. (Perhaps combineLatestAll with something to mark an event as "handled", but that "something" has been a bit elusive.) Would appreciate any pointers in that regard.

Also, with the unhandled event approach, there is a chance that if only part of a page loads (or perhaps, if the page loads with a smaller size than the one it had when it was stored in history), the user might start interacting with the page, and trigger the unhandled event much later, in case something resizes the page to be tall enough.

Related issues

Fixes #7097.

To reproduce the issue, I would:

  1. Scroll down on the My Videos page.
  2. Open a video's "Manage" button
  3. Switch the connection in Firefox's Dev Tools / Network to Throttled (otherwise, reproducing on localhost is near impossible)
  4. Press the back button on the browser

Has this been tested?

  • 👍 yes, I added tests to the test suite
  • 💭 no, because this PR is a draft and still needs work
  • 🙅 no, because this PR does not update server code
  • 🙋 no, because I need help

@Chocobozzz

Copy link
Copy Markdown
Owner

Nice! Thank you!

@Chocobozzz Chocobozzz merged commit 45dbdb1 into Chocobozzz:develop Jul 9, 2025
3 checks passed
@bojidar-bg

Copy link
Copy Markdown
Contributor Author

BTW, this PR was made during a live stream—you can watch see the final reproduction and demonstration at 2:41:24 (:
Apologies for the delay with posting that link; uploading and transcoding the recording took forever 😂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Back History bug

2 participants