From f96842021649f2a21304fec9e16b687b88c7c433 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. --- js/src/common/components/Page.js | 11 +++++++++++ js/src/forum/components/DiscussionPage.js | 2 ++ 2 files changed, 13 insertions(+) diff --git a/js/src/common/components/Page.js b/js/src/common/components/Page.js index 0d0a4afd88..4db613649c 100644 --- a/js/src/common/components/Page.js +++ b/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/js/src/forum/components/DiscussionPage.js b/js/src/forum/components/DiscussionPage.js index c5812bf397..beb0b2a5d8 100644 --- a/js/src/forum/components/DiscussionPage.js +++ b/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. *