fix: restore chat input draft after reload in chats started from the home page (#29762)

Typing a message, uploading a file or toggling web search in a chat started from the home page was lost on reload: the input came back empty and the uploaded files were gone for good.

Drafts are kept per chat in sessionStorage, but the key was built from the route prop, which stays empty for these chats because creating the chat only swaps the URL with history.replaceState and never re-runs the route load. Drafts were written under the new-chat key while a reload of /c/<id> read the per-chat key. Falling back to the active chat id lines the two up, the same fallback loadChat already uses for this reason.

The Placeholder submit handler also cleared the bare key rather than the current one, which left a stale draft behind once a chat's messages had all been deleted.

Verified against the base commit on a local instance: on base the draft lands under chat-input and is lost on reload, with the change it lands under chat-input-<id> and both the text and the uploaded file come back. Image attachments stay excluded from drafts by design.

The model selection half of #29760 has a different cause and is not fixed here.

Refs #29760
This commit is contained in:
Classic298 2026-09-21 14:08:45 +02:00 • committed by GitHub
parent f16e9eabe3
commit f5967aebd7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4026,7 +4026,8 @@
const MAX_DRAFT_LENGTH = 5000;
let saveDraftTimeout: ReturnType<typeof setTimeout> | null = null;
const getDraftChatId = () => chatIdProp || null;
// chatIdProp is empty for chats started from the home page (URL set via replaceState)
const getDraftChatId = () => chatIdProp || $chatId || null;
const getChatInputDraft = () => ({
prompt,
@ -4629,7 +4630,7 @@
}
}}
on:submit={async (e) => {
clearDraft();
clearDraft(getDraftChatId());
if (e.detail || files.length > 0) {
await tick();
submitHandler(withSelectedText(e.detail));