diff --git a/ui/src/lib/navigation-scroll.test.ts b/ui/src/lib/navigation-scroll.test.ts index 8bd40f9ae20..4a30336a3c5 100644 --- a/ui/src/lib/navigation-scroll.test.ts +++ b/ui/src/lib/navigation-scroll.test.ts @@ -41,6 +41,37 @@ describe("navigation-scroll", () => { ).toBe(false); }); + it("resets scroll when navigating into the top-level issues page", () => { + expect( + shouldResetScrollOnNavigation({ + previousPathname: "/issues/PAP-1389", + pathname: "/issues", + navigationType: "PUSH", + state: null, + }), + ).toBe(true); + + expect( + shouldResetScrollOnNavigation({ + previousPathname: "/PAP/issues/PAP-1389", + pathname: "/PAP/issues", + navigationType: "REPLACE", + state: null, + }), + ).toBe(true); + }); + + it("does not reset issues page scroll on browser history restoration", () => { + expect( + shouldResetScrollOnNavigation({ + previousPathname: "/issues/PAP-1389", + pathname: "/issues", + navigationType: "POP", + state: null, + }), + ).toBe(false); + }); + it("resets scroll when navigating directly between issue detail routes", () => { expect( shouldResetScrollOnNavigation({ diff --git a/ui/src/lib/navigation-scroll.ts b/ui/src/lib/navigation-scroll.ts index bbe2b61c571..0629507da19 100644 --- a/ui/src/lib/navigation-scroll.ts +++ b/ui/src/lib/navigation-scroll.ts @@ -14,6 +14,7 @@ export function shouldResetScrollOnNavigation(params: { if (previousPathname === null) return false; if (previousPathname === pathname) return false; if (navigationType === "POP") return false; + if (isIssueIndexPath(pathname)) return true; if (isIssueDetailPathChange(previousPathname, pathname)) return true; return hasSidebarScrollResetState(state); } @@ -75,6 +76,14 @@ function isIssueDetailPathChange(previousPathname: string, pathname: string): bo return previousIssueRef !== null && nextIssueRef !== null && previousIssueRef !== nextIssueRef; } +function isIssueIndexPath(pathname: string): boolean { + const segments = pathname.split("/").filter(Boolean); + return ( + (segments.length === 1 && segments[0] === "issues") + || (segments.length === 2 && segments[1] === "issues") + ); +} + function readIssueDetailPathRef(pathname: string): string | null { const segments = pathname.split("/").filter(Boolean); if (segments.length === 2 && segments[0] === "issues") {