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:
1 parent
6eccc2859a
commit
9756468a8c
7 files changed
+499
-7
No files matched your search
+11
-2
@@ -19,6 +19,7 @@ import { matchSidebarShortcut } from "@/lib/sidebar-shortcuts";
|
||||
import type { SidebarDeleteItem } from "@/components/ChatList";
|
||||
import type { SettingsSectionKey } from "@/components/settings/SettingsView";
|
||||
import { StartupShell } from "@/components/StartupShell";
|
||||
import { ComposerDraftStore, clearStoredComposerDrafts } from "@/lib/composer-draft";
|
||||
import { activateReloadCache, clearReloadCache } from "@/lib/reload-cache";
|
||||
import { webuiThreadCache } from "@/lib/webui-thread-cache";
|
||||
import { ThreadVisibilityContext } from "@/hooks/useThreadVisibility";
|
||||
@@ -968,6 +969,7 @@ export default function App() {
|
||||
if (cancelled) return;
|
||||
if (isBootstrapAuthRequired(e)) {
|
||||
clearReloadCache();
|
||||
clearStoredComposerDrafts();
|
||||
webuiThreadCache.clear();
|
||||
setState({ status: "auth", failed: !!secret });
|
||||
} else {
|
||||
@@ -994,6 +996,7 @@ export default function App() {
|
||||
} catch (e) {
|
||||
if (isBootstrapAuthRequired(e)) {
|
||||
clearReloadCache();
|
||||
clearStoredComposerDrafts();
|
||||
webuiThreadCache.clear();
|
||||
setState({ status: "auth", failed: !!bootstrapSecretRef.current });
|
||||
}
|
||||
@@ -1044,6 +1047,7 @@ export default function App() {
|
||||
}
|
||||
clearSavedSecret();
|
||||
clearReloadCache();
|
||||
clearStoredComposerDrafts();
|
||||
webuiThreadCache.clear();
|
||||
setState({ status: "auth" });
|
||||
};
|
||||
@@ -1239,6 +1243,7 @@ function Shell({
|
||||
// Pane shells can unmount during navigation. Keep replay state for this app
|
||||
// session, pinning temporary chats because they cannot reload disk history.
|
||||
const retainedTemporaryChatIdsRef = useRef(new Set<string>());
|
||||
const [draftStore] = useState(() => new ComposerDraftStore());
|
||||
const [filePreviewStore] = useState(() => new FilePreviewStore());
|
||||
const [threadMessageCache] = useState(() => new ThreadMessageCache(
|
||||
(key) => retainedTemporaryChatIdsRef.current.has(key),
|
||||
@@ -1249,10 +1254,11 @@ function Shell({
|
||||
if (!retained.has(chatId)) {
|
||||
threadMessageCache.delete(chatId);
|
||||
filePreviewStore.delete(`websocket:${chatId}`);
|
||||
draftStore.delete(`websocket:${chatId}`);
|
||||
}
|
||||
}
|
||||
retainedTemporaryChatIdsRef.current = retained;
|
||||
}, [temporaryChatIds, threadMessageCache, filePreviewStore]);
|
||||
}, [temporaryChatIds, threadMessageCache, filePreviewStore, draftStore]);
|
||||
|
||||
const navigate = useCallback(
|
||||
(route: ShellRoute, options?: { replace?: boolean }) => {
|
||||
@@ -2336,6 +2342,7 @@ function Shell({
|
||||
return;
|
||||
}
|
||||
filePreviewStore.delete(item.key);
|
||||
draftStore.delete(item.key);
|
||||
}
|
||||
setPendingDelete(null);
|
||||
if (deletingActive) {
|
||||
@@ -2348,7 +2355,7 @@ function Shell({
|
||||
} catch (e) {
|
||||
console.error("Failed to delete session", e);
|
||||
}
|
||||
}, [pendingDelete, deleteChat, activeKey, activeTabState, navigate, topicSessions, filePreviewStore]);
|
||||
}, [pendingDelete, deleteChat, activeKey, activeTabState, navigate, topicSessions, filePreviewStore, draftStore]);
|
||||
|
||||
const onRequestDeleteMany = useCallback(async (items: SidebarDeleteItem[]) => {
|
||||
const uniqueItems = Array.from(new Map(items.map((item) => [item.key, item])).values());
|
||||
@@ -2913,6 +2920,7 @@ function Shell({
|
||||
temporaryChatIds={temporaryChatIds}
|
||||
messageCache={threadMessageCache}
|
||||
filePreviewStore={filePreviewStore}
|
||||
draftStore={draftStore}
|
||||
temporaryChatEnabled={temporaryChatEnabled}
|
||||
onTemporaryChatEnabledChange={
|
||||
!activeKey ? onTemporaryChatEnabledChange : undefined
|
||||
@@ -2961,6 +2969,7 @@ function Shell({
|
||||
temporaryChatIds={temporaryChatIds}
|
||||
messageCache={threadMessageCache}
|
||||
filePreviewStore={filePreviewStore}
|
||||
draftStore={draftStore}
|
||||
onToggleSidebar={toggleSidebar}
|
||||
onNewChat={onNewChat}
|
||||
onCreateChat={onCreateChat}
|
||||
|
||||
Reference in new issue
Block a user