Skip to content

Commit b0474bb

Browse files
fix(web): closing Settings leaves no forward stop on the closed modal
Stepping back with history.go kept the Settings entries in forward history, so Forward reopened the dismissed modal. Go back to the entry before the return page and push it again instead: the push drops the modal's entries, and history ends up as A, B with nothing ahead. Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 12fb958 commit b0474bb

2 files changed

Lines changed: 17 additions & 5 deletions

File tree

‎apps/web/src/components/sidebar/mainAppLocation.browser.test.tsx‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,13 @@ describe("main app return location", () => {
8686
await userEvent.click(screen.getByRole("button", { name: "Close modal" }));
8787
await vi.waitFor(() => expect(router.state.location.pathname).toBe(otherThreadPath));
8888

89+
router.history.forward();
90+
await vi.waitFor(() => expect(router.state.location.pathname).toBe(otherThreadPath));
8991
router.history.back();
9092
await vi.waitFor(() => expect(router.state.location.pathname).toBe(THREAD_PATH));
93+
router.history.forward();
94+
await vi.waitFor(() => expect(router.state.location.pathname).toBe(otherThreadPath));
95+
router.history.forward();
96+
await vi.waitFor(() => expect(router.state.location.pathname).toBe(otherThreadPath));
9197
});
9298
});

‎apps/web/src/components/sidebar/mainAppLocation.ts‎

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,16 @@ export function useCloseAppModal() {
5757
const navigate = useNavigate();
5858
const router = useRouter();
5959
return () => {
60-
// Step back over the modal's entries so a closed modal is not a stop in history.
61-
const steps =
62-
router.state.location.state.__TSR_index - (appModalReturnHistoryIndex ?? Infinity);
63-
if (steps > 0) return router.history.go(-steps);
64-
return navigate({ href: appModalReturnHref ?? mainAppHref ?? "/" });
60+
const href = appModalReturnHref ?? mainAppHref ?? "/";
61+
const returnIndex = appModalReturnHistoryIndex ?? 0;
62+
const steps = router.state.location.state.__TSR_index - returnIndex;
63+
if (returnIndex === 0 || steps <= 0) return navigate({ href });
64+
// Go back to the entry before the return page and push it again: only a push drops the
65+
// modal's entries from forward history, and reusing the old entry avoids a duplicate stop.
66+
const unsubscribe = router.history.subscribe(() => {
67+
unsubscribe();
68+
void navigate({ href });
69+
});
70+
router.history.go(-(steps + 1));
6571
};
6672
}

0 commit comments

Comments
 (0)