refactor(webui): derive footer spacing from thread tail

This commit is contained in:
chengyongru authored and chengyongru committed 2026-09-20 11:47:27 +08:00
1 parent 900675e7f8
commit 0f3cabb16d
4 files changed
+23 -20

No files matched your search

+6 -7
View File
@@ -66,8 +66,8 @@ interface MessageBubbleProps {
temporary?: boolean;
/** When false, hide this message's copy button. Default true. */
showCopyAction?: boolean;
/** Whether this is the final assistant text slice before the next user turn. */
isTerminalAssistantSlice?: boolean;
/** Whether this message is the final display unit in the thread. */
isThreadTail?: boolean;
cliApps?: CliAppInfo[];
mcpPresets?: McpPresetInfo[];
slashCommands?: SlashCommand[];
@@ -332,7 +332,7 @@ export function MessageBubble({
isTurnStreaming = false,
temporary = false,
showCopyAction = true,
isTerminalAssistantSlice = true,
isThreadTail = true,
cliApps = [],
mcpPresets = [],
slashCommands = [],
@@ -486,7 +486,7 @@ export function MessageBubble({
? completedAt
: message.createdAt;
const assistantTimestampLabel =
message.role === "assistant" && !message.isStreaming
message.role === "assistant" && !message.isStreaming && !isTurnStreaming
? formatMessageEndTime(assistantTimestamp)
: "";
const showCompletedAt =
@@ -494,8 +494,7 @@ export function MessageBubble({
&& (!empty || hasReasoning || media.length > 0);
const showAssistantTimestamp =
assistantTimestampLabel.length > 0
&& (!empty || hasReasoning || media.length > 0)
&& (!isTurnStreaming || isTerminalAssistantSlice);
&& (!empty || hasReasoning || media.length > 0);
const assistantTimestampTitle = showAssistantTimestamp ? fmtDateTime(assistantTimestamp) : "";
const showAutomationTrigger = showAssistantTimestamp && automationSourceLabel.length > 0;
const showAssistantFooterRow =
@@ -505,7 +504,7 @@ export function MessageBubble({
&& (!empty || hasReasoning || media.length > 0);
const showAssistantFooterSlot =
hasAssistantFooterContent
&& (showAssistantFooterRow || isTerminalAssistantSlice);
&& (showAssistantFooterRow || ((message.isStreaming || isTurnStreaming) && isThreadTail));
return (
<div className="w-full text-[15px]" style={{ lineHeight: "var(--cjk-line-height)" }}>
{hasReasoning ? (
+14 -10
View File
@@ -143,6 +143,14 @@ export function ThreadMessages({
unit.type === "message" && unit.message.role === "assistant" && forkFlags[index]
? nextUserIndex
: undefined;
const unitTurnStreaming = unit.type === "activity"
? liveActivityClusterIndices.has(index)
: isStreaming && (
unit.message.turnId && activeTurnId !== null
? unit.message.turnId === activeTurnId
: index > currentTurnStartIndex
);
const isThreadTail = index === units.length - 1;
if (
unit.type === "message"
&& unit.message.role === "user"
@@ -158,15 +166,8 @@ export function ThreadMessages({
userPromptId={userPromptId}
hasBodyBelow={hasBodyBelow}
deferOffscreenRender={deferOffscreenRender}
isTurnStreaming={
unit.type === "activity"
? liveActivityClusterIndices.has(index)
: isStreaming && (
unit.message.turnId && activeTurnId !== null
? unit.message.turnId === activeTurnId
: index > currentTurnStartIndex
)
}
isTurnStreaming={unitTurnStreaming}
isThreadTail={isThreadTail}
retryStatus={
unit.type === "activity" && liveActivityClusterIndices.has(index)
? retryStatus
@@ -256,6 +257,7 @@ interface ThreadDisplayUnitProps {
hasBodyBelow: boolean;
deferOffscreenRender: boolean;
isTurnStreaming: boolean;
isThreadTail: boolean;
retryStatus: RetryStatus | null;
forkIndex?: number;
showForkBoundary: boolean;
@@ -278,6 +280,7 @@ const ThreadDisplayUnit = memo(function ThreadDisplayUnit({
hasBodyBelow,
deferOffscreenRender,
isTurnStreaming,
isThreadTail,
retryStatus,
forkIndex,
showForkBoundary,
@@ -343,8 +346,8 @@ const ThreadDisplayUnit = memo(function ThreadDisplayUnit({
<MessageBubble
message={unit.message}
isTurnStreaming={isTurnStreaming}
isThreadTail={isThreadTail}
temporary={temporary}
isTerminalAssistantSlice={forkIndex !== undefined}
cliApps={cliApps}
mcpPresets={mcpPresets}
slashCommands={slashCommands}
@@ -369,6 +372,7 @@ function threadDisplayUnitPropsEqual(
&& previous.hasBodyBelow === next.hasBodyBelow
&& previous.deferOffscreenRender === next.deferOffscreenRender
&& previous.isTurnStreaming === next.isTurnStreaming
&& previous.isThreadTail === next.isThreadTail
&& previous.retryStatus === next.retryStatus
&& previous.forkIndex === next.forkIndex
&& previous.showForkBoundary === next.showForkBoundary
+2 -2
View File
@@ -868,7 +868,7 @@ describe("MessageBubble", () => {
expect(visibleFooter).toHaveClass("mt-2", "min-h-8", "opacity-100");
});
it("omits hidden footer space for an intermediate assistant answer", () => {
it("omits footer space when an active answer is no longer the tail", () => {
const message: UIMessage = {
id: "a-intermediate",
role: "assistant",
@@ -880,7 +880,7 @@ describe("MessageBubble", () => {
<MessageBubble
message={message}
isTurnStreaming
isTerminalAssistantSlice={false}
isThreadTail={false}
/>,
);
+1 -1
View File
@@ -1532,7 +1532,7 @@ describe("ThreadMessages", () => {
.closest<HTMLElement>("[data-thread-display-unit]")!;
expect(firstAnswer.querySelector("[data-assistant-footer]")).not.toBeInTheDocument();
expect(finalAnswer.querySelector("[data-assistant-footer]"))
.toHaveAttribute("data-state", "visible");
.toHaveAttribute("data-state", "reserved");
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Copy"]')).toHaveLength(1);
expect(container.querySelectorAll('[data-assistant-footer] [aria-label="Fork"]')).toHaveLength(1);