Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DEV: Move all scroll position reset/remember logic to a shared service #22552

Merged
merged 12 commits into from Jul 13, 2023

Conversation

davidtaylorhq
Copy link
Member

Previously we were implementing scroll reset/memorization on a per-page basis. Many of these approaches relied on the didInsertElement hook, which is no longer appropriate since Discourse changed to use the 'loading slider' strategy for page transitions.

This commit rips out all of our custom scroll resetting/memorizing, and implements those things in a generic service. There are two features:

  1. After every route transition, scroll to the top of the page
  2. When using browser back/forward buttons, restore the last known scroll position for those routes

Previously we were implementing scroll reset/memorization on a per-page basis. Many of these approaches relied on the `didInsertElement` hook, which is no longer appropriate since Discourse changed to use the 'loading slider' strategy for page transitions.

This commit rips out all of our custom scroll resetting/memorizing, and implements those things in a generic service. There are two features:

1. After every route transition, scroll to the top of the page
2. When using browser back/forward buttons, restore the last known scroll position for those routes
@@ -6,6 +6,17 @@ let popstateFired = false;
const supportsHistoryState = window.history && "state" in window.history;
const popstateCallbacks = [];

function _uuid() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This 'uuid' feature is part of upstream's "history-location" routing adapter, which we eventually intend to migrate to.

https://github.com/emberjs/ember.js/blob/9e51c3629d18f53bfc057ac94987b5d27eb7cdfa/packages/%40ember/routing/history-location.ts#L12-L19

@davidtaylorhq davidtaylorhq marked this pull request as ready for review July 12, 2023 11:58
Co-authored-by: Jarek Radosz <jradosz@gmail.com>
Copy link
Contributor

@jjaffeux jjaffeux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, lots of old/hacky stuff gone 💯

davidtaylorhq and others added 2 commits July 12, 2023 13:16
@discoursebot
Copy link

This pull request has been mentioned on Discourse Meta. There might be relevant details there:

https://meta.discourse.org/t/clicking-home-page-logo-no-longer-takes-you-to-top-of-the-page/270856/10

Using the lastViewedTopicId indiscriminately can cause strange scrolling behavior when navigating to a **different** topic list after viewing a topic. We only want to refocus the topic when going 'back' to the same topic list which originally triggered the navigation.
@davidtaylorhq davidtaylorhq merged commit dfe94ba into main Jul 13, 2023
13 checks passed
@davidtaylorhq davidtaylorhq deleted the scroll-manager branch July 13, 2023 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants