Skip to content

Commit b6f96e9

Browse files
committed
optimize scroll position saving (fix #1145)
1 parent b769978 commit b6f96e9

File tree

2 files changed

+2
-3
lines changed

2 files changed

+2
-3
lines changed

src/util/push-state.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export function setStateKey (key: string) {
3838
}
3939

4040
export function pushState (url?: string, replace?: boolean) {
41+
saveScrollPosition()
4142
// try...catch the pushState call to get around Safari
4243
// DOM Exception 18 where it limits to 100 pushState calls
4344
const history = window.history
@@ -48,7 +49,6 @@ export function pushState (url?: string, replace?: boolean) {
4849
_key = genKey()
4950
history.pushState({ key: _key }, '', url)
5051
}
51-
saveScrollPosition()
5252
} catch (e) {
5353
window.location[replace ? 'replace' : 'assign'](url)
5454
}

src/util/scroll.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,11 @@ const positionStore = Object.create(null)
88

99
export function setupScroll () {
1010
window.addEventListener('popstate', e => {
11+
saveScrollPosition()
1112
if (e.state && e.state.key) {
1213
setStateKey(e.state.key)
1314
}
1415
})
15-
16-
window.addEventListener('scroll', saveScrollPosition)
1716
}
1817

1918
export function handleScroll (

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy