FIX: Scroll to the last position when navigating back to the tag topic list. (#11496)

Scrolling was not working as expected after clicking the browser back button and navigating back to the tag topic list. We need to wrap the scroll inside a debounce function to ensure that the "window.pageYOffset" property is populated before our function runs.
This commit is contained in:
Roman Rizzi 2020-12-16 15:23:12 -03:00 committed by GitHub
parent 230fe0427e
commit 4d1bc3a491
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -1,9 +1,9 @@
import { alias, reads } from "@ember/object/computed"; import { alias, reads } from "@ember/object/computed";
import { debounce, schedule } from "@ember/runloop";
import discourseComputed, { observes } from "discourse-common/utils/decorators"; import discourseComputed, { observes } from "discourse-common/utils/decorators";
import Component from "@ember/component"; import Component from "@ember/component";
import LoadMore from "discourse/mixins/load-more"; import LoadMore from "discourse/mixins/load-more";
import { on } from "@ember/object/evented"; import { on } from "@ember/object/evented";
import { schedule } from "@ember/runloop";
export default Component.extend(LoadMore, { export default Component.extend(LoadMore, {
tagName: "table", tagName: "table",
@ -73,7 +73,17 @@ export default Component.extend(LoadMore, {
let scrollTo = this.session.get("topicListScrollPosition"); let scrollTo = this.session.get("topicListScrollPosition");
if (scrollTo && scrollTo >= 0) { if (scrollTo && scrollTo >= 0) {
schedule("afterRender", () => $(window).scrollTop(scrollTo + 1)); schedule("afterRender", () => {
debounce(
this,
function () {
if (this.element && !this.isDestroying && !this.isDestroyed) {
$(window).scrollTop(scrollTo + 1);
}
},
0
);
});
} }
}, },

View File

@ -59,6 +59,7 @@
order=order order=order
ascending=ascending ascending=ascending
changeSort=(action "changeSort") changeSort=(action "changeSort")
scrollOnLoad=true
}} }}
{{/discovery-topics-list}} {{/discovery-topics-list}}
{{/if}} {{/if}}