mirror of
https://github.com/paperclipai/paperclip.git
synced 2026-10-24 18:19:05 +02:00
fix(ui): settle restored draft submissions only once
Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
1 parent
2bedd0f23b
commit
dece40fd5e
2 files changed
+52
-1
No files matched your search
@@ -3276,6 +3276,57 @@ describe("IssueChatThread", () => {
|
||||
act(() => root.unmount());
|
||||
});
|
||||
|
||||
it("settles a restored submission only once through StrictMode effect replay", () => {
|
||||
const key = "strict-restored-submission";
|
||||
const attemptId = "aaf8228f-0be7-45ae-a104-6fbe0af6f1d3";
|
||||
const submitted = "One text-only save interrupted by reload.";
|
||||
const nextDraft = "A newer draft written while delivery was pending.";
|
||||
localStorage.setItem(key, `${submitted}\n\n${nextDraft}`);
|
||||
localStorage.setItem(`${key}:submission:v1`, JSON.stringify({
|
||||
version: 1,
|
||||
draftKey: key,
|
||||
attemptId,
|
||||
reviewed: false,
|
||||
nextDraftOffset: submitted.length + 2,
|
||||
submittedAttachmentIds: [],
|
||||
}));
|
||||
const root = createRoot(container);
|
||||
try {
|
||||
act(() => root.render(
|
||||
<StrictMode>
|
||||
<MemoryRouter>
|
||||
<IssueChatThread
|
||||
comments={[{
|
||||
...issueChatLongThreadComments[0]!,
|
||||
id: "confirmed-restored-comment",
|
||||
body: submitted,
|
||||
authorAgentId: null,
|
||||
authorUserId: "user-1",
|
||||
clientRequestId: attemptId,
|
||||
}]}
|
||||
currentUserId="user-1"
|
||||
linkedRuns={[]}
|
||||
timelineEvents={[]}
|
||||
liveRuns={[]}
|
||||
onAdd={async () => {}}
|
||||
draftKey={key}
|
||||
enableLiveTranscriptPolling={false}
|
||||
/>
|
||||
</MemoryRouter>
|
||||
</StrictMode>,
|
||||
));
|
||||
expect(container.querySelector<HTMLTextAreaElement>(
|
||||
'textarea[aria-label="Issue chat editor"]',
|
||||
)?.value).toBe(nextDraft);
|
||||
expect(localStorage.getItem(key)).toBe(nextDraft);
|
||||
expect(localStorage.getItem(`${key}:submission:v1`)).toBeNull();
|
||||
expect(container.textContent).not.toContain("We couldn’t confirm");
|
||||
} finally {
|
||||
act(() => root.unmount());
|
||||
}
|
||||
expect(localStorage.getItem(key)).toBe(nextDraft);
|
||||
});
|
||||
|
||||
it("stores and restores the composer draft per issue key", () => {
|
||||
vi.useFakeTimers();
|
||||
const root = createRoot(container);
|
||||
|
||||
@@ -4824,7 +4824,7 @@ const IssueChatComposer = forwardRef<
|
||||
if (!uncertainSubmission || !confirmedSubmissionIds.has(uncertainSubmission.attemptId)) return;
|
||||
const nextDraft = uncertainSubmission.nextDraftOffset === undefined
|
||||
? "" : bodyRef.current.slice(uncertainSubmission.nextDraftOffset);
|
||||
if (draftKey) settleDraftSubmission(draftKey, uncertainSubmission.attemptId, nextDraft);
|
||||
if (draftKey && !settleDraftSubmission(draftKey, uncertainSubmission.attemptId, nextDraft)) return;
|
||||
setUncertainSubmission(null);
|
||||
setBody(nextDraft);
|
||||
bodyRef.current = nextDraft;
|
||||
|
||||
Reference in new issue
Block a user