From f3f25e76af607c90829f06659a05a5232c745e73 Mon Sep 17 00:00:00 2001 From: Blaine Motsinger Date: Thu, 2 Apr 2026 17:46:05 -0500 Subject: [PATCH] Fix scroll/focus shift on htmx navigation When htmx performs boosted navigation (full-page content swap), it defaults to scrolling the viewport to show the new content via scrollIntoViewOnBoost. Combined with RT's menu expansion on htmx:afterSettle, this causes the viewport to jump around unexpectedly after navigation. This fix: 1. Disables htmx's automatic scrollIntoViewOnBoost behavior 2. Adds explicit scroll-to-top only for body-target swaps (boosted nav), not for widget/element reloads which should preserve scroll position --- share/static/js/util.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/share/static/js/util.js b/share/static/js/util.js index 2e508e28e2..2da118754d 100644 --- a/share/static/js/util.js +++ b/share/static/js/util.js @@ -1796,3 +1796,15 @@ jQuery.fn.combobox.Constructor.prototype.clearElement = function () { htmx.config.includeIndicatorStyles = false; htmx.config.scrollBehavior = 'smooth'; + +// Disable automatic scroll-to-content on boosted navigation +// which causes unwanted viewport shifts when combined with menu expansion +htmx.config.scrollIntoViewOnBoost = false; + +// Scroll to top only on full-page boosted navigations (body target), +// not widget/element reloads which should preserve scroll position +document.body.addEventListener('htmx:afterSwap', function(evt) { + if (evt.target === document.body) { + window.scrollTo(0, 0); + } +});