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

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"assets/javascripts/bundle.js": "assets/javascripts/bundle.837e8062.min.js", "assets/javascripts/bundle.js": "assets/javascripts/bundle.630a9b34.min.js",
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.837e8062.min.js.map", "assets/javascripts/bundle.js.map": "assets/javascripts/bundle.630a9b34.min.js.map",
"assets/javascripts/vendor.js": "assets/javascripts/vendor.c1fcc1cc.min.js", "assets/javascripts/vendor.js": "assets/javascripts/vendor.c1fcc1cc.min.js",
"assets/javascripts/vendor.js.map": "assets/javascripts/vendor.c1fcc1cc.min.js.map", "assets/javascripts/vendor.js.map": "assets/javascripts/vendor.c1fcc1cc.min.js.map",
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.3bc815f0.min.js", "assets/javascripts/worker/search.js": "assets/javascripts/worker/search.3bc815f0.min.js",

View File

@ -175,7 +175,7 @@
</div> </div>
{% block scripts %} {% block scripts %}
<script src="{{ 'assets/javascripts/vendor.c1fcc1cc.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/vendor.c1fcc1cc.min.js' | url }}"></script>
<script src="{{ 'assets/javascripts/bundle.837e8062.min.js' | url }}"></script> <script src="{{ 'assets/javascripts/bundle.630a9b34.min.js' | url }}"></script>
{%- set translations = {} -%} {%- set translations = {} -%}
{%- for key in [ {%- for key in [
"clipboard.copy", "clipboard.copy",

View File

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