fix(webui): preserve sidebar state after failed initial fetch (#6009)
* fix(webui): wait for sidebar state before persisting edits * test(webui): load sidebar state in temporary chat fixtures * fix(webui): preserve sidebar pushes during initial reads * fix(webui): require successful session reads before pruning Treat sidebar initialization and session-list completeness as separate permissions. Retain sidebar metadata, workbench panes, activity markers, and workspace overrides when the session list fails or only a partial reload cache is available. Add integration coverage for recovery with and without cached sessions, successful deletion reconciliation, and successful empty session lists. * test(webui): align sidebar recovery fixture with current schema Remove obsolete preview and timestamp settings from the raw API fixture. Assert supported view preferences while retaining exact metadata and workbench comparisons. --------- Co-authored-by: chengyongru <chengyongru.ai@gmail.com>
This commit is contained in:
1 parent
f101a24571
commit
d2aaa8e54b
5 files changed
+286
-22
No files matched your search
+11
-8
@@ -1199,18 +1199,21 @@ function Shell({
|
||||
const {
|
||||
sessions,
|
||||
loading,
|
||||
error: sessionsError,
|
||||
refresh,
|
||||
createChat,
|
||||
forkChat,
|
||||
deleteChat,
|
||||
getSessionAutomations,
|
||||
} = useSessions();
|
||||
// Failed reads retain an empty list or partial reload cache, not proof of deletion.
|
||||
const sessionsLoaded = !loading && sessionsError === null;
|
||||
const {
|
||||
state: sidebarState,
|
||||
loading: sidebarStateLoading,
|
||||
update: updateSidebarState,
|
||||
} =
|
||||
useSidebarState(sessions, !loading);
|
||||
useSidebarState(sessions, sessionsLoaded);
|
||||
const initialRouteRef = useRef<ShellRoute | null>(null);
|
||||
if (!initialRouteRef.current) initialRouteRef.current = readShellRoute();
|
||||
const [activeKey, setActiveKey] = useState<string | null>(
|
||||
@@ -1599,7 +1602,7 @@ function Shell({
|
||||
}, [refreshWorkspaces]);
|
||||
|
||||
useEffect(() => {
|
||||
if (loading) return;
|
||||
if (!sessionsLoaded) return;
|
||||
const knownChatIds = new Set(sessions.map((session) => session.chatId));
|
||||
setUpdatedChatIds((current) => {
|
||||
const next = new Set(
|
||||
@@ -1611,16 +1614,16 @@ function Shell({
|
||||
const entries = Object.entries(current).filter(([chatId]) => knownChatIds.has(chatId));
|
||||
return entries.length === Object.keys(current).length ? current : Object.fromEntries(entries);
|
||||
});
|
||||
}, [loading, sessions]);
|
||||
}, [sessionsLoaded, sessions]);
|
||||
|
||||
useEffect(() => {
|
||||
if (loading || sidebarStateLoading) return;
|
||||
if (!sessionsLoaded || sidebarStateLoading) return;
|
||||
const validKeys = new Set(sessions.map((session) => session.key));
|
||||
updateWorkbenchState((current) => {
|
||||
return reconcileWorkbench(current, validKeys);
|
||||
});
|
||||
}, [
|
||||
loading,
|
||||
sessionsLoaded,
|
||||
sidebarStateLoading,
|
||||
sessions,
|
||||
updateWorkbenchState,
|
||||
@@ -2780,12 +2783,12 @@ function Shell({
|
||||
: activeKey;
|
||||
|
||||
const sidebarProps = {
|
||||
sessions: sidebarTopicSessions,
|
||||
temporarySessions: temporarySessionList,
|
||||
sessions: sidebarStateLoading ? [] : sidebarTopicSessions,
|
||||
temporarySessions: sidebarStateLoading ? [] : temporarySessionList,
|
||||
activeKey: !managingConnections && view === "chat"
|
||||
? (temporaryChatActive ? activeKey : activeSidebarKey)
|
||||
: null,
|
||||
loading,
|
||||
loading: loading || sidebarStateLoading,
|
||||
newChatActive: !managingConnections && view === "chat" && activeKey === null,
|
||||
onNewChat,
|
||||
onSelect: onSelectSidebarItem,
|
||||
|
||||
Reference in new issue
Block a user