From 725bc1d8d2e56812b89e456cc5260246b6d2f870 Mon Sep 17 00:00:00 2001 From: David DeCarmine Date: Tue, 11 Jul 2017 16:34:51 -0600 Subject: [PATCH 1/2] fix scroll when going back to initial route --- src/util/scroll.js | 1 + test/e2e/specs/scroll-behavior.js | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/src/util/scroll.js b/src/util/scroll.js index 18b62ee18..b2d00b950 100644 --- a/src/util/scroll.js +++ b/src/util/scroll.js @@ -7,6 +7,7 @@ import { getStateKey, setStateKey } from './push-state' const positionStore = Object.create(null) export function setupScroll () { + window.history.replaceState({ key: getStateKey() }, '') window.addEventListener('popstate', e => { saveScrollPosition() if (e.state && e.state.key) { diff --git a/test/e2e/specs/scroll-behavior.js b/test/e2e/specs/scroll-behavior.js index 7075f681b..9a816c265 100644 --- a/test/e2e/specs/scroll-behavior.js +++ b/test/e2e/specs/scroll-behavior.js @@ -20,6 +20,26 @@ module.exports = { return window.pageYOffset === 100 }, null, 'restore scroll position on back') + // with manual scroll restoration + // https://developers.google.com/web/updates/2015/09/history-api-scroll-restoration + .execute(function () { + window.scrollTo(0, 100) + history.scrollRestoration = 'manual' + }) + .click('li:nth-child(2) a') + .assert.containsText('.view', 'foo') + .execute(function () { + window.scrollTo(0, 200) + window.history.back() + }) + .assert.containsText('.view', 'home') + .assert.evaluate(function () { + return window.pageYOffset === 100 + }, null, 'restore scroll position on back with manual restoration') + .execute(function () { + history.scrollRestoration = 'auto' + }) + // scroll on a popped entry .execute(function () { window.scrollTo(0, 50) From 53d0f81c6540aead0ee70252643a25fe7ecd2fab Mon Sep 17 00:00:00 2001 From: Eduardo San Martin Morote Date: Sun, 23 Jul 2017 11:32:50 +0200 Subject: [PATCH 2/2] Update scroll.js --- src/util/scroll.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/util/scroll.js b/src/util/scroll.js index b2d00b950..b50af05eb 100644 --- a/src/util/scroll.js +++ b/src/util/scroll.js @@ -7,6 +7,7 @@ import { getStateKey, setStateKey } from './push-state' const positionStore = Object.create(null) export function setupScroll () { + // Fix for #1585 for Firefox window.history.replaceState({ key: getStateKey() }, '') window.addEventListener('popstate', e => { saveScrollPosition()