From f5967aebd7f17c99e1be2b4c9c506a7083e8e536 Mon Sep 17 00:00:00 2001 From: Classic298 <27028174+Classic298@users.noreply.github.com> Date: Mon, 21 Sep 2026 14:08:45 +0200 Subject: [PATCH] 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/ 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- 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 --- src/lib/components/chat/Chat.svelte | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/components/chat/Chat.svelte b/src/lib/components/chat/Chat.svelte index 8c95b6d2d8..fd0e1bbac1 100644 --- a/src/lib/components/chat/Chat.svelte +++ b/src/lib/components/chat/Chat.svelte @@ -4026,7 +4026,8 @@ const MAX_DRAFT_LENGTH = 5000; let saveDraftTimeout: ReturnType | 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));