Skip to content

Commit

Permalink
Don't use browser scroll restore in DiscussionPage (#2476)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
askvortsov1 authored Nov 30, 2020
1 parent d5e124b commit f968420
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
11 changes: 11 additions & 0 deletions js/src/common/components/Page.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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() {
Expand Down
2 changes: 2 additions & 0 deletions js/src/forum/components/DiscussionPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ export default class DiscussionPage extends Page {
oninit(vnode) {
super.oninit(vnode);

this.useBrowserScrollRestoration = false;

/**
* The discussion that is being viewed.
*
Expand Down

0 comments on commit f968420

Please sign in to comment.