diff --git a/src/util/scroll.js b/src/util/scroll.js index 18b62ee18..b50af05eb 100644 --- a/src/util/scroll.js +++ b/src/util/scroll.js @@ -7,6 +7,8 @@ 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() 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)