Sidebar loses scroll position on navigation #85
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
m's report (2026-05-25 13:12)
Scope
Clicking a sidebar nav item triggers a full page reload → the sidebar re-renders → the user's scroll position is lost. With many entries in the sidebar (Werkzeuge group, projects list, etc.), this is annoying.
What to do
Two viable approaches — pick whichever is cleaner given the current architecture:
Option A — Persist + restore scroll position
scrollToptosessionStorage(key:paliad.sidebar.scroll).scrollTopfrom sessionStorage.Option B — Don't reload the sidebar at all
#mainor whichever target wraps the page body).hx-push-url="true"(or equivalent) so browser back/forward works.<a href="...">and let HTMX intercept normal clicks only.Recommended (R): Option B if the codebase already uses HTMX-style partial swaps for any page. Otherwise Option A is the lighter touch.
What to verify
Files most likely touched
frontend/src/components/Sidebar.tsxfrontend/src/client/sidebar.ts(if exists)Hard rules
go build ./... && go test ./internal/... && cd frontend && bun run buildclean.mai/<worker>/sidebar-scroll-preserve.Out of scope
Reporting
mai report completedwith branch + SHAs + chosen approach (A or B with justification) + verification path: scroll the sidebar to a Werkzeuge child entry → click into a project → confirm sidebar still shows the same Werkzeuge child entry without scrolling back to top.Fixed via Option A (sessionStorage persist+restore). HTMX isn't used anywhere in the codebase, so Option B would have meant introducing a new dependency for what is essentially a 25-line behavioural fix — not worth it. Option A also matches the established pattern in
frontend/src/client/projects.ts/client/views.ts, which both usesessionStoragefor ephemeral per-tab state.What landed
Branch:
mai/hermes/gitster-sidebar-losesCommit:
228ae1b— single file,frontend/src/client/sidebar.ts(+53)SCROLL_KEY = "paliad.sidebar.scroll"matching the key the issue specified.readStoredScroll()reads fromsessionStorage, falls back to 0 on missing/malformed/negative.applySidebarScroll(nav, px)setsnav.scrollTop(browser clamps to[0, max], so a stale value pointing past the current scrollHeight is harmless).initSidebarScrollRestore(sidebar)is wired intoinitSidebar()right afterinitSidebarResize(sidebar): synchronous restore on init + passivescrolllistener that persistsnav.scrollTopon every move.reapplySidebarScroll()is called frominitUserViewsGroup()after/api/user-viewsresolves — the synchronous restore happens before user-views are appended into the Ansichten group, so without this nudge a saved scrollTop pointing below the Ansichten group would land on the wrong row after the async layout shift.Verification
cd frontend && bun run build— clean (i18n codegen: 2786 keys, data-i18n attributes clean).go build ./...— clean.go test ./internal/...— all pass.paliad.sidebar.scrollconfirmed indist/assets/*.jsbundles.projects.ts/views.tspattern. Recommend a quick live smoke after merge+deploy: scroll the sidebar to a Werkzeuge child → click into a project → confirm sidebar still shows the same Werkzeuge child without snapping to top.Hard rules — checked
<a href>; the only existing click listener (closeMobile()on mobile) doesn'tpreventDefault. New tab opens with its ownsessionStorage, scroll starts at 0 — matches expectation.initSidebar()runs on every page load and the synchronous restore hits before paint.Out of scope (per issue) — confirmed not touched
Trade-offs
reapplySidebarScroll()nudge because the views group hydrates after init. If a future async hydrator gets added to the sidebar (e.g. project list), it should also callreapplySidebarScroll()after mutating the DOM. Documented inline above the helper.localStoragewould persist across sessions;sessionStorageis what the issue spec asked for and is the right call here.Ready for review/merge.