Repository navigation
fix(web): offer undo after unpinning a thread #10744
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
juliusmarminge
merged 4 commits into
pingdotgg:main
from
saphid:fix/web-unpin-undo-20260908
Sep 21, 2026
Merged
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
64ed611
fix(web): offer undo after unpinning a thread
github-actions[bot] d04ece4
fix(web): invalidate stale unpin undo actions
github-actions[bot] 8a31fca
refactor(web): pin and reorder just expire unpin Undo
saphid c6ffee9
refactor(web): share thread Undo claims and toast lifecycle
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import { describe, expect, it } from "vite-plus/test"; | ||
|
|
||
| import * as ThreadPinAction from "./threadPinAction"; | ||
|
|
||
| describe("pin action ownership", () => { | ||
| it("does not revive the first Undo after a later pin and unpin", () => { | ||
| const firstUnpin = ThreadPinAction.begin("env/thread"); | ||
| ThreadPinAction.invalidate("env/thread"); | ||
| const secondUnpin = ThreadPinAction.begin("env/thread"); | ||
| expect(firstUnpin.isCurrent()).toBe(false); | ||
| expect(secondUnpin.isCurrent()).toBe(true); | ||
| firstUnpin.finish(); | ||
| expect(secondUnpin.isCurrent()).toBe(true); | ||
| secondUnpin.finish(); | ||
| expect(firstUnpin.isCurrent()).toBe(false); | ||
| }); | ||
|
|
||
| it("rejects a late unpin completion after a newer pin started", () => { | ||
| const pendingUnpin = ThreadPinAction.begin("env/late"); | ||
| ThreadPinAction.invalidate("env/late"); | ||
| expect(pendingUnpin.isCurrent()).toBe(false); | ||
| }); | ||
|
|
||
| it("expires an Undo without invalidating another environment or thread", () => { | ||
| const first = ThreadPinAction.begin("one/thread"); | ||
| const otherEnvironment = ThreadPinAction.begin("two/thread"); | ||
| const otherThread = ThreadPinAction.begin("one/other"); | ||
| first.finish(); | ||
| expect(first.isCurrent()).toBe(false); | ||
| expect(otherEnvironment.isCurrent()).toBe(true); | ||
| expect(otherThread.isCurrent()).toBe(true); | ||
| otherEnvironment.finish(); | ||
| otherThread.finish(); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // Shared across hook instances so sidebar, header and menu actions invalidate each other. | ||
| const currentActions = new Map<string, symbol>(); | ||
|
|
||
| /** Claims a thread's pin state for one unpin Undo; any later claim or invalidation expires it. */ | ||
| export function begin(key: string) { | ||
| const token = Symbol(); | ||
| currentActions.set(key, token); | ||
| const isCurrent = () => currentActions.get(key) === token; | ||
| return { | ||
| isCurrent, | ||
| finish: () => { | ||
| if (isCurrent()) currentActions.delete(key); | ||
| }, | ||
| }; | ||
| } | ||
|
|
||
| /** Expires any outstanding Undo for the thread, e.g. when it is pinned or reordered. */ | ||
| export function invalidate(key: string) { | ||
| currentActions.delete(key); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| import { EnvironmentId, ThreadId } from "@t3tools/contracts"; | ||
| import { afterEach, describe, expect, it, vi } from "vite-plus/test"; | ||
|
|
||
| import { useThreadActions } from "./useThreadActions"; | ||
| import { threadEnvironment } from "../state/threads"; | ||
| import { toastManager } from "../components/ui/toast"; | ||
|
|
||
| const commands = vi.hoisted(() => ({ pin: vi.fn(), unpin: vi.fn() })); | ||
| vi.mock("react", async (original) => ({ | ||
| ...(await original<typeof import("react")>()), | ||
| useCallback: (callback: unknown) => callback, | ||
| useMemo: (create: () => unknown) => create(), | ||
| useRef: (value: unknown) => ({ current: value }), | ||
| })); | ||
| vi.mock("@tanstack/react-router", () => ({ useRouter: () => ({}) })); | ||
| vi.mock("./useSettings", () => ({ useClientSettings: () => false })); | ||
| vi.mock("./useHandleNewThread", () => ({ useNewThreadHandler: () => vi.fn() })); | ||
| vi.mock("../composerDraftStore", () => ({ useComposerDraftStore: () => vi.fn() })); | ||
| vi.mock("../terminalUiStateStore", () => ({ useTerminalUiStateStore: () => vi.fn() })); | ||
| vi.mock("../uiStateStore", () => ({ useUiStateStore: () => vi.fn() })); | ||
| vi.mock("../state/entities", async (original) => ({ | ||
| ...(await original<typeof import("../state/entities")>()), | ||
| readEnvironmentSupportsPinning: () => true, | ||
| readEnvironmentSupportsPinReorder: () => true, | ||
| readThreadShell: () => ({ title: "Thread", pinOrderKey: "a0" }), | ||
| })); | ||
| vi.mock("../state/use-atom-command", () => ({ | ||
| useAtomCommand: (command: unknown) => | ||
| command === threadEnvironment.pin | ||
| ? commands.pin | ||
| : command === threadEnvironment.unpin | ||
| ? commands.unpin | ||
| : vi.fn(), | ||
| })); | ||
|
|
||
| afterEach(() => vi.restoreAllMocks()); | ||
|
|
||
| describe("unpin Undo", () => { | ||
| it("ignores an old toast across hook instances and still restores the latest unpin", async () => { | ||
| commands.pin.mockResolvedValue({ _tag: "Success", value: undefined }); | ||
| commands.unpin.mockResolvedValue({ _tag: "Success", value: undefined }); | ||
| const add = vi.spyOn(toastManager, "add").mockReturnValue("toast"); | ||
| vi.spyOn(toastManager, "close").mockImplementation(() => {}); | ||
| const sidebar = useThreadActions(); | ||
| const header = useThreadActions(); | ||
| const target = { | ||
| environmentId: EnvironmentId.make("undo-env"), | ||
| threadId: ThreadId.make("thread"), | ||
| }; | ||
| await sidebar.unpinThread(target); | ||
| const staleUndo = add.mock.calls[0]?.[0].actionProps?.onClick; | ||
| await header.pinThread(target, { orderKey: "a1" }); | ||
| await header.unpinThread(target); | ||
| const latestUndo = add.mock.calls[1]?.[0].actionProps?.onClick; | ||
| expect(staleUndo).toBeTypeOf("function"); | ||
| expect(latestUndo).toBeTypeOf("function"); | ||
| const event = {} as Parameters<NonNullable<typeof staleUndo>>[0]; | ||
| staleUndo?.(event); | ||
| expect(commands.pin).toHaveBeenCalledTimes(1); | ||
| latestUndo?.(event); | ||
| expect(commands.pin).toHaveBeenCalledTimes(2); | ||
| expect(commands.pin).toHaveBeenLastCalledWith({ | ||
| environmentId: target.environmentId, | ||
| input: { threadId: target.threadId, orderKey: "a0" }, | ||
| }); | ||
| latestUndo?.(event); | ||
| expect(commands.pin).toHaveBeenCalledTimes(2); | ||
| }); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.