From 6351c2354fea55b3f4a9dc60036bf882002bb506 Mon Sep 17 00:00:00 2001 From: Toby Zerner <toby.zerner@gmail.com> Date: Thu, 10 Mar 2016 17:55:35 +1030 Subject: [PATCH] Fix browser back button losing scroll position. ref #835 --- framework/core/js/forum/dist/app.js | 8 +++++++- framework/core/js/forum/src/components/IndexPage.js | 6 +++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/framework/core/js/forum/dist/app.js b/framework/core/js/forum/dist/app.js index 951bf29e2..eea99fcbe 100644 --- a/framework/core/js/forum/dist/app.js +++ b/framework/core/js/forum/dist/app.js @@ -23455,7 +23455,13 @@ System.register('flarum/components/IndexPage', ['flarum/extend', 'flarum/compone var scrollTop = app.cache.scrollTop; $('#app').css('min-height', $(window).height() + heroHeight); - $(window).scrollTop(scrollTop - (app.cache.heroHeight - heroHeight)); + + // Scroll to the remembered position. We do this after a short delay so that + // it happens after the browser has done its own "back button" scrolling, + // which isn't right. https://github.com/flarum/core/issues/835 + setTimeout(function () { + return $(window).scrollTop(scrollTop - app.cache.heroHeight + heroHeight); + }, 1); app.cache.heroHeight = heroHeight; diff --git a/framework/core/js/forum/src/components/IndexPage.js b/framework/core/js/forum/src/components/IndexPage.js index d85867b94..9760f688e 100644 --- a/framework/core/js/forum/src/components/IndexPage.js +++ b/framework/core/js/forum/src/components/IndexPage.js @@ -103,7 +103,11 @@ export default class IndexPage extends Page { const scrollTop = app.cache.scrollTop; $('#app').css('min-height', $(window).height() + heroHeight); - $(window).scrollTop(scrollTop - (app.cache.heroHeight - heroHeight)); + + // Scroll to the remembered position. We do this after a short delay so that + // it happens after the browser has done its own "back button" scrolling, + // which isn't right. https://github.com/flarum/core/issues/835 + setTimeout(() => $(window).scrollTop(scrollTop - app.cache.heroHeight + heroHeight), 1); app.cache.heroHeight = heroHeight;