From 540e7edf37a16d95da30276fce72e7d45dbc84d7 Mon Sep 17 00:00:00 2001 From: Lanius Trolling Date: Wed, 9 Oct 2024 21:40:39 -0400 Subject: [PATCH] Fix Fetch+History fragment loading (again) --- src/jvmMain/resources/static/init.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/jvmMain/resources/static/init.js b/src/jvmMain/resources/static/init.js index b377ef2..26affe6 100644 --- a/src/jvmMain/resources/static/init.js +++ b/src/jvmMain/resources/static/init.js @@ -101,9 +101,9 @@ (async function () { const prevUrl = new URL(window.location.href); - const newState = {"href": url.href, "index": history.state.index + 1}; + const newState = {"href": url.href, "hash": url.hash, "index": history.state.index + 1}; - if (stateMode === "pop" && history.state.href === "") { + if (stateMode === "pop" && history.state.hash === "") { window.scroll(0, history.state.scroll); return; } else if (stateMode !== "pop" && url.pathname === prevUrl.pathname && url.search === prevUrl.search) { @@ -116,7 +116,7 @@ history.replaceState(newState, "", url); } - const scrollToElement = document.querySelector(url.hash); + const scrollToElement = url.hash === "" ? null : document.querySelector(url.hash); if (scrollToElement != null) { scrollToElement.scrollIntoView(true); } @@ -153,7 +153,7 @@ return; } - const redirectUrl = new URL(redirectJsonBody.target, window.location.origin) + const redirectUrl = new URL(redirectJsonBody.target, window.location.origin); if (!goToPage(redirectUrl, "push")) { window.location.href = redirectUrl.href; } @@ -190,7 +190,7 @@ return true; } - history.replaceState({"href": window.location.href, "index": 0}, ""); + history.replaceState({"href": window.location.href, "hash": window.location.hash, "index": 0}, ""); let isWindowScrollTicking = false; window.addEventListener("scroll", () => { -- 2.25.1