From 35228b4b2732c2f551a464a38b17bdaeda27d9e7 Mon Sep 17 00:00:00 2001 From: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com> Date: Mon, 30 Nov 2020 14:01:08 -0500 Subject: [PATCH] Don't use browser scroll restore in DiscussionPage (#2476) Although native browser scroll restorations have become quite powerful, it interferes with Flarum's PostStream, so if we're on a DiscussionPage, we use manual scroll restoration. --- framework/core/js/src/common/components/Page.js | 11 +++++++++++ .../core/js/src/forum/components/DiscussionPage.js | 2 ++ 2 files changed, 13 insertions(+) diff --git a/framework/core/js/src/common/components/Page.js b/framework/core/js/src/common/components/Page.js index 0d0a4afd8..4db613649 100644 --- a/framework/core/js/src/common/components/Page.js +++ b/framework/core/js/src/common/components/Page.js @@ -29,6 +29,13 @@ export default class Page extends Component { * @type {Boolean} */ this.scrollTopOnCreate = true; + + /** + * Whether the browser should restore scroll state on refreshes. + * + * @type {Boolean} + */ + this.useBrowserScrollRestoration = true; } oncreate(vnode) { @@ -41,6 +48,10 @@ export default class Page extends Component { if (this.scrollTopOnCreate) { $(window).scrollTop(0); } + + if ('scrollRestoration' in history) { + history.scrollRestoration = this.useBrowserScrollRestoration ? 'auto' : 'manual'; + } } onremove() { diff --git a/framework/core/js/src/forum/components/DiscussionPage.js b/framework/core/js/src/forum/components/DiscussionPage.js index c5812bf39..beb0b2a5d 100644 --- a/framework/core/js/src/forum/components/DiscussionPage.js +++ b/framework/core/js/src/forum/components/DiscussionPage.js @@ -18,6 +18,8 @@ export default class DiscussionPage extends Page { oninit(vnode) { super.oninit(vnode); + this.useBrowserScrollRestoration = false; + /** * The discussion that is being viewed. *