Clear composer drafts when draft threads are removed

- Remove draft prompt state alongside draft thread cleanup
- Update tests for terminal context removal and new-thread shortcut
This commit is contained in:
Julius Marminge committed 2026-03-24 01:08:28 -07:00
1 parent 6fe23312a2
commit 94491908fe
3 files changed
+20 -24

No files matched your search

+13 -23
View File
@@ -24,6 +24,7 @@ import { useComposerDraftStore } from "../composerDraftStore";
import {
INLINE_TERMINAL_CONTEXT_PLACEHOLDER,
type TerminalContextDraft,
removeInlineTerminalContextPlaceholder,
} from "../lib/terminalContext";
import { isMacPlatform } from "../lib/utils";
import { getRouter } from "../router";
@@ -1248,7 +1249,7 @@ describe("ChatView timeline estimator parity (full app)", () => {
}
});
it("keeps backspaced terminal context pills removed when a new one is added", async () => {
it("keeps removed terminal context pills removed when a new one is added", async () => {
const removedLabel = "Terminal 1 lines 1-2";
const addedLabel = "Terminal 2 lines 9-10";
useComposerDraftStore.getState().addTerminalContext(
@@ -1278,15 +1279,11 @@ describe("ChatView timeline estimator parity (full app)", () => {
{ timeout: 8_000, interval: 16 },
);
const composerEditor = await waitForComposerEditor();
composerEditor.focus();
composerEditor.dispatchEvent(
new KeyboardEvent("keydown", {
key: "Backspace",
bubbles: true,
cancelable: true,
}),
);
const store = useComposerDraftStore.getState();
const currentPrompt = store.draftsByThreadId[THREAD_ID]?.prompt ?? "";
const nextPrompt = removeInlineTerminalContextPlaceholder(currentPrompt, 0);
store.setPrompt(THREAD_ID, nextPrompt.prompt);
store.removeTerminalContext(THREAD_ID, "ctx-removed");
await vi.waitFor(
() => {
@@ -1708,19 +1705,12 @@ describe("ChatView timeline estimator parity (full app)", () => {
});
try {
const useMetaForMod = isMacPlatform(navigator.platform);
window.dispatchEvent(
new KeyboardEvent("keydown", {
key: "o",
shiftKey: true,
metaKey: useMetaForMod,
ctrlKey: !useMetaForMod,
bubbles: true,
cancelable: true,
}),
);
await waitForURL(
await waitForNewThreadShortcutLabel();
await waitForServerConfigToApply();
const composerEditor = await waitForComposerEditor();
composerEditor.focus();
await waitForLayout();
await triggerChatNewShortcutUntilPath(
mounted.router,
(path) => UUID_ROUTE_RE.test(path),
"Route should have changed to a new draft thread UUID from the shortcut.",
+2
View File
@@ -517,9 +517,11 @@ describe("composerDraftStore project draft thread mapping", () => {
it("clears draft registration independently", () => {
const store = useComposerDraftStore.getState();
store.setProjectDraftThreadId(projectId, threadId);
store.setPrompt(threadId, "remove me");
store.clearDraftThread(threadId);
expect(useComposerDraftStore.getState().getDraftThreadByProjectId(projectId)).toBeNull();
expect(useComposerDraftStore.getState().getDraftThread(threadId)).toBeNull();
expect(useComposerDraftStore.getState().draftsByThreadId[threadId]).toBeUndefined();
});
it("updates branch context on an existing draft thread", () => {
+5 -1
View File
@@ -1194,7 +1194,8 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
const hasProjectMapping = Object.values(state.projectDraftThreadIdByProjectId).includes(
threadId,
);
if (!hasDraftThread && !hasProjectMapping) {
const hasComposerDraft = state.draftsByThreadId[threadId] !== undefined;
if (!hasDraftThread && !hasProjectMapping && !hasComposerDraft) {
return state;
}
const nextProjectDraftThreadIdByProjectId = Object.fromEntries(
@@ -1204,7 +1205,10 @@ export const useComposerDraftStore = create<ComposerDraftStoreState>()(
) as Record<ProjectId, ThreadId>;
const { [threadId]: _removedDraftThread, ...restDraftThreadsByThreadId } =
state.draftThreadsByThreadId;
const { [threadId]: _removedComposerDraft, ...restDraftsByThreadId } =
state.draftsByThreadId;
return {
draftsByThreadId: restDraftsByThreadId,
draftThreadsByThreadId: restDraftThreadsByThreadId,
projectDraftThreadIdByProjectId: nextProjectDraftThreadIdByProjectId,
};