fix(webui): show skeleton while conversation history loads

This commit is contained in:
chengyongru authored and chengyongru committed 2026-10-20 22:01:40 +08:00
1 parent 85bee83247
commit 14d9e6ed0d
7 files changed
+176 -16

No files matched your search

@@ -0,0 +1,23 @@
import { useTranslation } from "react-i18next";
import { SkeletonStatus } from "@/components/settings/shared/SkeletonStatus";
export function ThreadLoadingSkeleton() {
const { t } = useTranslation();
return (
<SkeletonStatus label={t("thread.loadingConversation")} className="space-y-8 pt-12">
<div className="thread-message-row">
<div className="ml-auto h-10 w-2/5 rounded-floating bg-muted/60" />
</div>
<div className="thread-message-row space-y-3">
<div className="h-3 w-4/5 rounded bg-muted/60" />
<div className="h-3 w-full rounded bg-muted/60" />
<div className="h-3 w-3/5 rounded bg-muted/60" />
</div>
<div className="thread-message-row space-y-3">
<div className="h-3 w-3/4 rounded bg-muted/60" />
<div className="h-3 w-1/2 rounded bg-muted/60" />
</div>
</SkeletonStatus>
);
}
+11 -8
View File
@@ -29,6 +29,7 @@ import {
toModelBadgeInfo,
} from "@/components/thread/model-preset";
import { ThreadHeader } from "@/components/thread/ThreadHeader";
import { ThreadLoadingSkeleton } from "@/components/thread/ThreadLoadingSkeleton";
import { StreamErrorNotice } from "@/components/thread/StreamErrorNotice";
import { ThreadViewport, type ThreadViewportHandle } from "@/components/thread/ThreadViewport";
import { useNanobotStream, type SendAttachment, type SendOptions } from "@/hooks/useNanobotStream";
@@ -938,6 +939,9 @@ export function ThreadShell({
chatId, initial, hasPendingToolCalls, handleTurnEnd, handleStreamDetach, completedTurnIds,
);
const displayMessages = useMemo(() => projectWebuiThreadMessages(messages), [messages]);
const normalizedHistory = useMemo(() => projectWebuiThreadMessages(historical), [historical]);
// The response can arrive one commit before its messages reach the viewport.
const initialHistoryLoading = loading || (normalizedHistory.length > 0 && displayMessages.length === 0);
const promptNavigation = usePromptHistory(historyKey, historyVersion, displayMessages);
const updateNavigationMessages = promptNavigation.updateMessages;
@@ -1139,7 +1143,7 @@ export function ThreadShell({
chatId,
]);
const showHeroComposer = displayMessages.length === 0 && !loading;
const showHeroComposer = displayMessages.length === 0 && !initialHistoryLoading;
const composerVariant = showHeroComposer ? emptyComposerVariant : "thread";
const wasShowingHeroComposerRef = useRef(showHeroComposer);
const sessionModelPreset = session?.modelPreset?.trim() || null;
@@ -1269,9 +1273,9 @@ export function ThreadShell({
const canonicalCompletedTurnIds = useMemo(() => Array.from(new Set([
...completedTurnIds,
...(!completionIdsProvided && !hasPendingToolCalls && historyActiveTurnId === null
? completedAssistantTurnIds(projectWebuiThreadMessages(historical))
? completedAssistantTurnIds(normalizedHistory)
: []),
])), [completedTurnIds, completionIdsProvided, hasPendingToolCalls, historical, historyActiveTurnId]);
])), [completedTurnIds, completionIdsProvided, hasPendingToolCalls, normalizedHistory, historyActiveTurnId]);
const lastRunTurnId = chatId ? client.getRunTurnId(chatId) : null;
const completedRunTurnId = chatId && lastRunTurnId && client.isRunCompleted(chatId, lastRunTurnId)
@@ -1298,7 +1302,6 @@ export function ThreadShell({
)
)
);
const normalizedHistory = projectWebuiThreadMessages(historical);
// Completion is a fact about a turn, even when a newer local turn prevents
// this snapshot from settling the conversation's current run.
client.fenceCanonicalCompletedTurns(chatId, canonicalCompletedTurnIds);
@@ -1407,6 +1410,7 @@ export function ThreadShell({
canonicalCompletedTurnIds,
completionIdsProvided,
historical,
normalizedHistory,
historyVersion,
historyContinuity,
historyLineage,
@@ -2000,10 +2004,8 @@ export function ThreadShell({
</>
);
const emptyState = loading ? (
<div className="flex h-full items-center justify-center text-sm text-muted-foreground">
{t("thread.loadingConversation")}
</div>
const emptyState = initialHistoryLoading ? (
<ThreadLoadingSkeleton />
) : (
<div className="flex w-full flex-col items-center text-center animate-in fade-in-0 slide-in-from-bottom-2 [animation-duration:220ms] motion-reduce:animate-none">
<HeroGreeting text={t(heroGreetingKey)} />
@@ -2085,6 +2087,7 @@ export function ThreadShell({
runStartedAt={currentRunStartedAt}
retryStatus={retryStatus}
emptyState={emptyState}
initialLoading={initialHistoryLoading}
composer={composerPortalTarget === undefined ? composer : null}
activeTurnId={viewportTurnId}
activeTurnStartedHere={activeTurnStartedHere}
+12 -7
View File
@@ -48,6 +48,7 @@ interface ThreadViewportProps {
composer?: ReactNode;
navigationFrame?: HTMLElement | null;
emptyState?: ReactNode;
initialLoading?: boolean;
scrollToBottomSignal?: number;
activeTurnId?: string | null;
activeTurnStartedHere?: boolean;
@@ -249,6 +250,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
composer,
navigationFrame,
emptyState,
initialLoading = false,
scrollToBottomSignal = 0,
activeTurnId: liveTurnId = null,
activeTurnStartedHere = false,
@@ -384,6 +386,7 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
}
const hasTaskContent = useHasSubagentContent();
const hasMessages = messages.length > 0 || (hasTaskContent && conversationReady);
const hasThreadLayout = hasMessages || initialLoading;
useLayoutEffect(() => {
scrollRef.current = hasMessages
? messageRegionRef.current
@@ -1045,11 +1048,11 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
>
<div
ref={contentRef}
data-testid={!hasMessages ? "thread-welcome-layout" : undefined}
data-layout={hasComposer ? (hasMessages ? "thread" : "hero") : "external"}
data-testid={!hasThreadLayout ? "thread-welcome-layout" : undefined}
data-layout={hasComposer ? (hasThreadLayout ? "thread" : "hero") : "external"}
className={cn(
"thread-layout mx-auto grid min-h-full w-full",
hasMessages
hasThreadLayout
? "h-full"
: "max-w-[72rem] px-3 pb-[calc(0.75rem+env(safe-area-inset-bottom))] pt-6 sm:px-4 sm:py-12",
)}
@@ -1097,8 +1100,10 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
ref={emptyStateRef}
data-testid="thread-empty-region"
className={cn(
"row-start-1 flex min-h-0 min-w-0 w-full items-center justify-center",
hasComposer && "sm:items-end sm:pb-8",
"row-start-1 min-h-0 min-w-0 w-full",
initialLoading
? "overflow-hidden"
: cn("flex items-center justify-center", hasComposer && "sm:items-end sm:pb-8"),
)}
>
{emptyState}
@@ -1130,12 +1135,12 @@ export const ThreadViewport = forwardRef<ThreadViewportHandle, ThreadViewportPro
}}
className={cn(
"row-start-2 z-10 w-full",
hasMessages ? "thread-composer-dock relative" : "relative self-center",
hasThreadLayout ? "thread-composer-dock relative" : "relative self-center",
)}
>
<div
className={cn(
hasMessages
hasThreadLayout
? "px-3 pb-[calc(0.75rem+env(safe-area-inset-bottom))] sm:px-4"
: "",
)}