-
Notifications
You must be signed in to change notification settings - Fork 9
Open
Labels
bugSomething isn't workingSomething isn't working
Description
This is just for keeping track of the discussion in #86 (comment). (if the URL being displayed has an anchor, every time the page is patched the client would scroll to the anchor again).
Proposed fix (to the current, non-multisite ema) is:
src/Ema/Server.hs | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/src/Ema/Server.hs b/src/Ema/Server.hs
index cb98105..882f188 100644
--- a/src/Ema/Server.hs
+++ b/src/Ema/Server.hs
@@ -278,6 +278,8 @@ wsClientShim =
function init(reconnecting) {
// The route current DOM is displaying
let routeVisible = document.location.pathname;
+ // If client should scroll to anchor on next DOM patch
+ let pendingHashChange = false;
const verb = reconnecting ? "Reopening" : "Opening";
console.log(`ema: $${verb} conn $${wsUrl} ...`);
@@ -300,6 +302,7 @@ wsClientShim =
function switchRoute(path, hash = "") {
console.log(`ema: → Switching to $${path + hash}`);
window.history.pushState({}, "", path + hash);
+ if (hash) { pendingHashChange = true };
sendObservePath(path);
}
@@ -358,11 +361,12 @@ wsClientShim =
window.scrollTo({ top: 0});
routeVisible = document.location.pathname;
}
- if (window.location.hash) {
+ if (pendingHashChange && window.location.hash) {
var el = document.querySelector(window.location.hash);
if (el !== null) {
el.scrollIntoView({ behavior: 'smooth' });
}
+ pendingHashChange = false;
}
watchCurrentRoute();
};
--
2.35.1Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't working