Fixed restoration of scroll offset on page refresh

This commit is contained in:
squidfunk
2020-03-28 13:56:58 +01:00
parent f38d0a8d64
commit 4d370fe903
6 changed files with 14 additions and 17 deletions

View File

@@ -349,20 +349,18 @@ export function initialize(config: unknown) {
setToggle("drawer", false)
})
/* Hack: ensure that page loads restore scroll offset */
fromEvent(window, "beforeunload")
.subscribe(() => {
history.scrollRestoration = "auto"
})
// instant loading
if (config.features.includes("instant")) {
/* Disable automatic scroll restoration, as it doesn't work nicely */
location$
.pipe(
skip(1),
take(1)
)
.subscribe(() => {
console.log("disabled automatic scroll restoration")
if ("scrollRestoration" in history)
history.scrollRestoration = "manual"
})
if ("scrollRestoration" in history)
history.scrollRestoration = "manual"
/* Resolve relative links for stability */
for (const selector of [
@@ -375,7 +373,6 @@ export function initialize(config: unknown) {
setupInstantLoading({
document$, link$, location$, viewport$
})
}
/* ----------------------------------------------------------------------- */