Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/util/scroll.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
20 changes: 20 additions & 0 deletions test/e2e/specs/scroll-behavior.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down