💾 fix: Restore Send State From Saved Drafts (#17822)

This commit is contained in:
Marco Beretta 2026-11-05 09:54:32 +01:00 • committed by GitHub
parent c0187d1de4
commit e1adcda55b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 2 deletions

View file

@ -254,6 +254,7 @@ const ChatForm = memo(function ChatForm({
* answer box, or is locked behind the batch card that owns the answer. A
* collapsed batch is neither, it hands the composer back to the thread. */
const composerReserved = answerMode.composerAnswers || answerMode.composerLocked;
const textValue = useWatch({ control: methods.control, name: 'text' });
const { consumeDraft, preserveText, settleText } = useAutoSave({
index,
@ -437,7 +438,6 @@ const ChatForm = memo(function ChatForm({
),
});
const textValue = useWatch({ control: methods.control, name: 'text' });
const interfaceDirection = useDirection();
/** An empty `dir="auto"` field resolves to LTR, which would park an RTL interface's placeholder on
* the wrong edge, so the empty field follows the interface until text gives it a direction. */

View file

@ -233,6 +233,17 @@ describe('ChatForm URL submission', () => {
jest.useRealTimers();
});
it('enables Send when an existing conversation restores a saved draft', async () => {
const conversation = { ...initialConversation, conversationId: 'existing-chat' };
setDraft({ id: conversation.conversationId, value: 'restored draft' });
mountComposer(conversation, { query: '' });
await act(async () => jest.advanceTimersByTime(100));
expect(screen.getByTestId('text-input')).toHaveValue('restored draft');
expect(screen.getByRole('button', { name: 'Send message' })).toBeEnabled();
});
it('processes a queued prompt URL after ordinary conversation navigation without remounting', async () => {
const source = { ...initialConversation, conversationId: 'source-chat' };
const view = mountComposer(source, { query: '' });

View file

@ -1,6 +1,12 @@
import { expect, test } from '@playwright/test';
import type { Page } from '@playwright/test';
import { sendMessage, selectMockEndpoint, MOCK_ENDPOINTS, NEW_CHAT_PATH } from '../helpers';
import {
sendMessageAndWaitForCompletion,
selectMockEndpoint,
MOCK_ENDPOINTS,
NEW_CHAT_PATH,
sendMessage,
} from '../helpers';
/**
* Save-drafts and temporary chat are app preferences the chat reads through the host's chat
@ -69,11 +75,15 @@ test.describe('chat settings owners', () => {
await setPreference(page, 'saveDrafts', true);
await page.reload();
await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);
await sendMessageAndWaitForCompletion(page, `draft-owner-${Date.now()}`);
await expect(page).toHaveURL(/\/c\/(?!new)[^/?]+$/);
const kept = `kept draft ${Date.now()}`;
await messageInput(page).fill(kept);
await expect.poll(() => storedDraftContains(page, kept)).toBe(true);
await page.reload();
await expect(messageInput(page)).toHaveValue(kept, { timeout: 20000 });
await expect(page.getByTestId('send-button')).toBeEnabled();
await messageInput(page).fill('');
await setPreference(page, 'saveDrafts', false);
@ -86,5 +96,6 @@ test.describe('chat settings owners', () => {
await page.reload();
await expect(messageInput(page)).toBeVisible({ timeout: 20000 });
await expect(messageInput(page)).toHaveValue('');
await expect(page.getByTestId('send-button')).toBeDisabled();
});
});