GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(web): keep later navigation when thread deletion completes (#33953) · Pipyakas/t3code@451e375

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/web/src/hooks
    • useThreadActions.permissions.test.ts
    • useThreadActions.ts
    • useThreadActions.undo.test.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/web/src/hooks/useThreadActions.permissions.test.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/hooks/useThreadActions.permissions.test.ts
+5-1Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ vi.mock("react", () => ({
5555
useRef: (current: unknown) => ({ current }),
5656
}));
5757
vi.mock("@tanstack/react-router", () => ({
58-
useRouter: () => ({ state: { location: { href: "/" }, matches: [] }, navigate: async () => {} }),
58+
useRouter: () => ({
59+
state: { location: { href: "/" }, matches: [] },
60+
history: { subscribe: () => () => {} },
61+
navigate: async () => {},
62+
}),
5963
}));
6064
vi.mock("../state/session", () => ({
6165
environmentSession: { sessionStateAtom: "session" },
Collapse file

‎apps/web/src/hooks/useThreadActions.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/hooks/useThreadActions.ts
+8-2Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,10 +588,16 @@ export function useThreadActions() {
588588
sortOrder: sidebarThreadSortOrder,
589589
now: new Date().toISOString(),
590590
});
591+
let navigatedDuringDelete = false;
592+
// The missing-thread redirect and the index draft replace this entry; any other history
593+
// action while the delete is pending is the user's own choice, which must win.
594+
const stopWatchingHistory = router.history.subscribe(({ action }) => {
595+
if (action.type !== "REPLACE") navigatedDuringDelete = true;
596+
});
591597
const deleteResult = await deleteThreadMutation({
592598
environmentId: threadRef.environmentId,
593599
input: { threadId: threadRef.threadId },
594-
});
600+
}).finally(stopWatchingHistory);
595601
if (deleteResult._tag === "Failure") {
596602
return deleteResult;
597603
}
@@ -615,7 +621,7 @@ export function useThreadActions() {
615621
clearTerminalUiState(threadRef);
616622
clearDeletedThreadPanelState(threadRef);
617623

618-
if (shouldNavigateToFallback) {
624+
if (shouldNavigateToFallback && !navigatedDuringDelete) {
619625
const fallbackThread = fallbackThreadId
620626
? readThreadShell(scopeThreadRef(threadRef.environmentId, fallbackThreadId))
621627
: null;
Collapse file

‎apps/web/src/hooks/useThreadActions.undo.test.ts‎

Copy file name to clipboardExpand all lines: apps/web/src/hooks/useThreadActions.undo.test.ts
+33-4Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,20 @@ const commands = vi.hoisted(() => ({
1919
snooze: vi.fn(),
2020
unsnooze: vi.fn(),
2121
}));
22-
const router = vi.hoisted(() => ({
23-
navigate: vi.fn(async () => {}),
24-
state: { location: { href: "/" }, matches: [{ params: {} as Record<string, string> }] },
25-
}));
22+
const router = vi.hoisted(() => {
23+
const listeners = new Set<(event: { action: { type: string } }) => void>();
24+
return {
25+
navigate: vi.fn(async () => {}),
26+
state: { location: { href: "/" }, matches: [{ params: {} as Record<string, string> }] },
27+
history: {
28+
listeners,
29+
subscribe: (listener: (event: { action: { type: string } }) => void) => {
30+
listeners.add(listener);
31+
return () => listeners.delete(listener);
32+
},
33+
},
34+
};
35+
});
2636
vi.mock("../state/use-atom-query-runner", () => ({ useAtomQueryRunner: () => vi.fn() }));
2737
vi.mock("../state/session", async (original) => ({
2838
...(await original<typeof import("../state/session")>()),
@@ -251,6 +261,25 @@ describe("archive navigation", () => {
251261
});
252262
});
253263

264+
describe("delete navigation", () => {
265+
it.each([
266+
{ type: "REPLACE", by: "the app's missing-thread redirect", fallsBack: true },
267+
{ type: "PUSH", by: "the user opening another thread", fallsBack: false },
268+
])("falls back: $fallsBack after $by while deleting", async ({ type, fallsBack }) => {
269+
router.state.matches[0]!.params = {
270+
environmentId: target.environmentId,
271+
threadId: target.threadId,
272+
};
273+
commands.delete.mockImplementation(async () => {
274+
for (const listener of router.history.listeners) listener({ action: { type } });
275+
return { _tag: "Success", value: undefined };
276+
});
277+
expect((await useThreadActions().deleteThread(target))._tag).toBe("Success");
278+
expect(router.navigate).toHaveBeenCalledTimes(fallsBack ? 1 : 0);
279+
expect(router.history.listeners.size).toBe(0);
280+
});
281+
});
282+
254283
describe("settle and snooze Undo", () => {
255284
it("un-settles from the notice and expires the Undo after a manual un-settle", async () => {
256285
const add = vi.spyOn(toastManager, "add").mockReturnValue("toast");

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.