Remember scroll position on back/forward and reload

BrowserRouter has no scroll handling and the browser's own restoration
runs before the page has loaded its data, so it lands short. Track the
window scroll per history entry in sessionStorage and restore it on POP,
retrying as the page grows until it fits, the user scrolls or 5 s pass.
Pushing a new pathname scrolls to the top; query-only pushes (table sort,
filter, page) keep the position.

Closes #1247

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bbassieandClaude Opus 5.5 committed 2026-11-21 02:43:57 +00:00
1 parent 8692ea3941
commit 33817bbe42
3 files changed
+203

No files matched your search

@@ -11,6 +11,7 @@ import AboutModal from "./AboutModal";
import Link from "./Link";
import { saveJson } from "../util/save_file";
import useScrollRestoration from "../util/useScrollRestoration";
import { useAccount } from "../model/account";
import { DraggingContext } from "../model/is_dragging";
import webUiPackage from "../../package.json";
@@ -50,6 +51,7 @@ function isActiveDropzone(element: HTMLElement | null): boolean {
export default function SiteLayout() {
let navigate = useNavigate();
useScrollRestoration();
let [currentSidebarPath, setCurrentSidebarPath] = useState<string | null>(null);
const screens = Grid.useBreakpoint();
// On phone screens the sidebar becomes an overlay drawer instead of a fixed sider.