fix(webui): preserve composer drafts across navigation and reloads (#5912)

* fix(webui): preserve composer drafts when switching sessions

* fix(webui): restore ordinary composer drafts after reload

* fix(webui): retain draft identity across composer remounts
This commit is contained in:
chengyongru authored and GitHub committed 2026-09-25 23:42:01 +08:00
1 parent 6eccc2859a
commit 9756468a8c
7 files changed
+499 -7

No files matched your search

+24 -3
View File
@@ -16,6 +16,7 @@ import { PromptNavigator } from "@/components/thread/PromptNavigator";
import { ModelFallbackNotice } from "@/components/thread/ModelFallbackNotice";
import { RecoveryNotice } from "@/components/thread/RecoveryNotice";
import { SessionInfoPopover } from "@/components/thread/SessionInfoPopover";
import type { ComposerDraftStore } from "@/lib/composer-draft";
import { ThreadComposer } from "@/components/thread/ThreadComposer";
import type {
ComposerContextUsage,
@@ -411,6 +412,7 @@ interface ThreadShellProps {
temporaryChatIds?: readonly string[];
messageCache?: ThreadMessageCache;
filePreviewStore?: FilePreviewStore;
draftStore?: ComposerDraftStore;
temporaryChatEnabled?: boolean;
onTemporaryChatEnabledChange?: (enabled: boolean) => void;
onToggleSidebar: () => void;
@@ -633,6 +635,7 @@ export function ThreadShell({
temporaryChatIds = [],
messageCache,
filePreviewStore,
draftStore,
temporaryChatEnabled = false,
onTemporaryChatEnabledChange,
onToggleSidebar,
@@ -739,7 +742,15 @@ export function ThreadShell({
const previewOpen = Boolean(activePreview);
const [filePreviewMaxWidth, setFilePreviewMaxWidth] = useState(FILE_PREVIEW_MAX_WIDTH);
const filePreviewWidth = clampFilePreviewWidth(previewState.width, filePreviewMaxWidth);
const [quotedContext, setQuotedContext] = useState<string | null>(null);
const draftKey = session?.key ?? (temporaryChatEnabled ? "new:temporary" : "new:chat");
const persistDraft = session ? !temporary : !temporaryChatEnabled;
const [quote, setQuote] = useState<{ key: string; text: string | null } | null>(null);
const quotedContext = quote?.key === draftKey
? quote.text
: draftStore?.get(draftKey, persistDraft)?.quotedContext ?? null;
const setQuotedContext = useCallback((text: string | null) => {
setQuote({ key: draftKey, text });
}, [draftKey]);
const [composerFocusSignal, setComposerFocusSignal] = useState(0);
const shellRef = useRef<HTMLElement | null>(null);
const composerSurfaceRef = useRef<HTMLDivElement | null>(null);
@@ -876,7 +887,6 @@ export function ThreadShell({
filePreviewCloseTimerRef.current = null;
}
setClosingPreview(null);
setQuotedContext(null);
setSubmittedViewportTurnId(null);
}, [previewSessionKey]);
@@ -896,7 +906,7 @@ export function ThreadShell({
const handleQuoteSelection = useCallback((text: string) => {
setQuotedContext(text);
setComposerFocusSignal((value) => value + 1);
}, []);
}, [setQuotedContext]);
useEffect(() => {
return () => {
@@ -1506,6 +1516,7 @@ export function ThreadShell({
activeViewportTurnByChatIdRef.current.set(chatId, submitted.turnId);
setSubmittedViewportTurnId(submitted.turnId);
}
return submitted !== null;
},
[chatId, send, withWorkspaceScope],
);
@@ -1715,6 +1726,10 @@ export function ThreadShell({
) : null}
{session ? (
<ThreadComposer
key={draftKey}
draftKey={draftKey}
draftStore={draftStore}
persistDraft={persistDraft}
onSend={handleThreadSend}
disabled={!chatId}
inputAriaLabel={composerInputAriaLabel}
@@ -1765,6 +1780,10 @@ export function ThreadShell({
/>
) : (
<ThreadComposer
key={draftKey}
draftKey={draftKey}
draftStore={draftStore}
persistDraft={persistDraft}
onSend={handleWelcomeSend}
disabled={booting}
inputAriaLabel={composerInputAriaLabel}
@@ -1808,6 +1827,8 @@ export function ThreadShell({
onWorkspaceScopeChange={onWorkspaceScopeChange}
transcriptionProvider={settingsSnapshot?.transcription?.provider}
ingressLimits={ingressLimits}
quotedContext={quotedContext}
onQuotedContextChange={setQuotedContext}
/>
)}
</>