mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-25 17:45:53 +01:00
fix(ui): flush pending composer drafts on teardown
This commit is contained in:
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);
|
||||
|
||||
Reference in new issue
Block a user