fix(ui): flush pending composer drafts on teardown

This commit is contained in:
scotttong committed 2026-08-07 17:09:00 -07:00
1 parent 76dec42d75
commit ddcaaebe57
2 files changed
+17 -1

No files matched your search

@@ -563,6 +563,21 @@ describe("TaskChatComposer", () => {
}
});
it("flushes a pending draft when the composer unmounts", () => {
vi.useFakeTimers();
try {
render(<TaskChatComposer onAdd={vi.fn()} workMode="standard" draftKey={KEY} />);
typeText("save before leaving");
flushSync(() => root?.unmount());
root = null;
expect(localStorage.getItem(KEY)).toBe("save before leaving");
} finally {
vi.useRealTimers();
}
});
it("clears the draft key on a successful send (not via the empty-body debounce)", async () => {
localStorage.setItem(KEY, "queued message");
const onAdd = vi.fn().mockResolvedValue(undefined);
@@ -188,8 +188,9 @@ export function TaskChatComposer({
useEffect(() => {
return () => {
if (draftTimer.current) clearTimeout(draftTimer.current);
if (draftKey) saveDraft(draftKey, bodyRef.current);
};
}, []);
}, [draftKey]);
const modeMeta = workModeMetaFor(pendingMode);
const canAcceptFiles = Boolean(onAttachImage || onImageUpload);