Sidebar collapse/expand button sometimes stops working until the page is reloaded
Description
What happens
Sometimes the sidebar's collapse/expand button (the panel icon at the top left of the desktop sidebar) stops doing anything when clicked. Reloading the page makes it work again. It isn't clear yet what causes it.
Suspected cause (not yet confirmed)
internal/server/static/app.js (around line 836) looks up the button once, at page load:
const sidebarToggle = document.querySelector("[data-sidebar-collapse-toggle]");
...
sidebarToggle.addEventListener("click", () => { ... });
The click handler is attached directly to that one element. If the element is ever replaced, the new button has no handler and stays dead until a full reload.
One likely way it gets replaced is htmx history restore. Sidebar and project links navigate with hx-push-url, and no hx-history-elt is set, so htmx snapshots <body>. Pressing Back or Forward then restores the page by swapping the body's HTML back in. That creates a fresh [data-sidebar-collapse-toggle] with no listener. The existing htmx:historyRestore listener (around line 1675) only calls syncSidebarActive, so it doesn't rebind anything.
To check this: open a page, navigate within the app by clicking a sidebar link, press Back, then click the collapse button.
mobileSidebarToggle and the other elements set up the same way at load could have the same problem.
Possible fix
Use a delegated listener: document.addEventListener("click", e => e.target.closest("[data-sidebar-collapse-toggle]") ...). Also look the button up again inside applySidebarCollapsed rather than holding a reference. Add a test or browser check that the toggle still works after a history restore.
Sub-issues
0Linked issues
0GitHub
0No branches or pull requests linked.