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
@@ -143,6 +143,7 @@ export function useSidebarState(
|
||||
const { client, token } = useClient();
|
||||
const tokenRef = useRef(token);
|
||||
const stateRef = useRef(DEFAULT_SIDEBAR_STATE);
|
||||
const loadedRef = useRef(false);
|
||||
const connectionOpenRef = useRef(client.status === "open");
|
||||
const pendingPersistenceRef = useRef<SidebarStatePayload | null>(null);
|
||||
const persistenceInFlightRef = useRef(false);
|
||||
@@ -154,29 +155,35 @@ export function useSidebarState(
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false;
|
||||
let retryTimer: ReturnType<typeof setTimeout> | undefined;
|
||||
setLoading(true);
|
||||
(async () => {
|
||||
const load = async () => {
|
||||
if (cancelled || loadedRef.current) return;
|
||||
try {
|
||||
const loaded = normalizeSidebarState(await fetchSidebarState(tokenRef.current));
|
||||
if (cancelled) return;
|
||||
if (cancelled || loadedRef.current) return;
|
||||
stateRef.current = loaded;
|
||||
loadedRef.current = true;
|
||||
setState(loaded);
|
||||
setLoading(false);
|
||||
} catch {
|
||||
if (cancelled) return;
|
||||
stateRef.current = DEFAULT_SIDEBAR_STATE;
|
||||
setState(DEFAULT_SIDEBAR_STATE);
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false);
|
||||
if (cancelled || loadedRef.current) return;
|
||||
// A failed read is not an empty store. Keep writes blocked until a
|
||||
// retry can load the saved state, including after gateway restarts.
|
||||
retryTimer = setTimeout(() => void load(), 3_000);
|
||||
}
|
||||
})();
|
||||
};
|
||||
void load();
|
||||
return () => {
|
||||
cancelled = true;
|
||||
clearTimeout(retryTimer);
|
||||
};
|
||||
}, []);
|
||||
|
||||
const flushPersistence = useCallback(() => {
|
||||
if (
|
||||
persistenceInFlightRef.current
|
||||
!loadedRef.current
|
||||
|| persistenceInFlightRef.current
|
||||
|| !connectionOpenRef.current
|
||||
|| pendingPersistenceRef.current === null
|
||||
) return;
|
||||
@@ -220,11 +227,14 @@ export function useSidebarState(
|
||||
) return;
|
||||
const loaded = normalizeSidebarState(incoming);
|
||||
stateRef.current = loaded;
|
||||
loadedRef.current = true;
|
||||
setState(loaded);
|
||||
setLoading(false);
|
||||
}), [client]);
|
||||
|
||||
const update = useCallback(
|
||||
async (updater: (current: SidebarStatePayload) => SidebarStatePayload) => {
|
||||
if (!loadedRef.current) return;
|
||||
const next = normalizeSidebarState(updater(stateRef.current));
|
||||
if (sameState(next, stateRef.current)) return;
|
||||
stateRef.current = next;
|
||||
|
||||
Reference in new issue
Block a user