Skip to content

Commit 47d87c5

Browse files
committed
refactor(web): drop chat bubble shells abstraction
The `chatBubbleShells` module introduced by the earlier refactor added indirection without meaningful payoff: - `UserMessageBubbleShell` / `AssistantMessageBubbleShell` are one-to-two-element wrappers over trivial Tailwind class strings; inlining them at the two call sites is cheaper than maintaining a shared module. - `ChatFontSizeScope` was only used by the settings preview. The live timeline sets `--chat-font-size` on the LegendList wrapper and `data-timeline-root` on each row, so the single-element helper never fit there. - The preview is decorative — pixel-perfect parity with the real bubble JSX isn't required, so cross-file coupling isn't earning us anything. Delete the module, restore inline bubble JSX in MessagesTimeline, and inline the wrapper + font-size scope in ChatFontSizePreview.
1 parent f09afc5 commit 47d87c5

3 files changed

Lines changed: 83 additions & 164 deletions

File tree

‎apps/web/src/components/chat/MessagesTimeline.tsx‎

Lines changed: 66 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ import {
3131
ZapIcon,
3232
} from "lucide-react";
3333
import { Button } from "../ui/button";
34-
import { AssistantMessageBubbleShell, UserMessageBubbleShell } from "./chatBubbleShells";
3534
import { buildExpandedImagePreview, ExpandedImagePreview } from "./ExpandedImagePreview";
3635
import { ProposedPlanCard } from "./ProposedPlanCard";
3736
import { ChangedFilesTree } from "./ChangedFilesTree";
@@ -311,70 +310,74 @@ function TimelineRowContent({ row }: { row: TimelineRow }) {
311310
const terminalContexts = displayedUserMessage.contexts;
312311
const canRevertAgentWork = typeof row.revertTurnCount === "number";
313312
return (
314-
<UserMessageBubbleShell>
315-
{userImages.length > 0 && (
316-
<div className="mb-2 grid max-w-[420px] grid-cols-2 gap-2">
317-
{userImages.map((image: NonNullable<TimelineMessage["attachments"]>[number]) => (
318-
<div
319-
key={image.id}
320-
className="overflow-hidden rounded-lg border border-border/80 bg-background/70"
321-
>
322-
{image.previewUrl ? (
323-
<button
324-
type="button"
325-
className="h-full w-full cursor-zoom-in"
326-
aria-label={`Preview ${image.name}`}
327-
onClick={() => {
328-
const preview = buildExpandedImagePreview(userImages, image.id);
329-
if (!preview) return;
330-
ctx.onImageExpand(preview);
331-
}}
313+
<div className="flex justify-end">
314+
<div className="group relative max-w-[80%] rounded-2xl rounded-br-sm border border-border bg-secondary px-4 py-3">
315+
{userImages.length > 0 && (
316+
<div className="mb-2 grid max-w-[420px] grid-cols-2 gap-2">
317+
{userImages.map(
318+
(image: NonNullable<TimelineMessage["attachments"]>[number]) => (
319+
<div
320+
key={image.id}
321+
className="overflow-hidden rounded-lg border border-border/80 bg-background/70"
332322
>
333-
<img
334-
src={image.previewUrl}
335-
alt={image.name}
336-
className="block h-auto max-h-[220px] w-full object-cover"
337-
/>
338-
</button>
339-
) : (
340-
<div className="flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-chat-xxs text-muted-foreground/70">
341-
{image.name}
323+
{image.previewUrl ? (
324+
<button
325+
type="button"
326+
className="h-full w-full cursor-zoom-in"
327+
aria-label={`Preview ${image.name}`}
328+
onClick={() => {
329+
const preview = buildExpandedImagePreview(userImages, image.id);
330+
if (!preview) return;
331+
ctx.onImageExpand(preview);
332+
}}
333+
>
334+
<img
335+
src={image.previewUrl}
336+
alt={image.name}
337+
className="block h-auto max-h-[220px] w-full object-cover"
338+
/>
339+
</button>
340+
) : (
341+
<div className="flex min-h-[72px] items-center justify-center px-2 py-3 text-center text-chat-xxs text-muted-foreground/70">
342+
{image.name}
343+
</div>
344+
)}
342345
</div>
343-
)}
344-
</div>
345-
))}
346-
</div>
347-
)}
348-
{(displayedUserMessage.visibleText.trim().length > 0 ||
349-
terminalContexts.length > 0) && (
350-
<UserMessageBody
351-
text={displayedUserMessage.visibleText}
352-
terminalContexts={terminalContexts}
353-
/>
354-
)}
355-
<div className="mt-1.5 flex items-center justify-end gap-2">
356-
<div className="flex items-center gap-1.5 opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover:opacity-100">
357-
{displayedUserMessage.copyText && (
358-
<MessageCopyButton text={displayedUserMessage.copyText} />
359-
)}
360-
{canRevertAgentWork && (
361-
<Button
362-
type="button"
363-
size="xs"
364-
variant="outline"
365-
disabled={ctx.isRevertingCheckpoint || ctx.isWorking}
366-
onClick={() => ctx.onRevertUserMessage(row.message.id)}
367-
title="Revert to this message"
368-
>
369-
<Undo2Icon className="size-3" />
370-
</Button>
371-
)}
346+
),
347+
)}
348+
</div>
349+
)}
350+
{(displayedUserMessage.visibleText.trim().length > 0 ||
351+
terminalContexts.length > 0) && (
352+
<UserMessageBody
353+
text={displayedUserMessage.visibleText}
354+
terminalContexts={terminalContexts}
355+
/>
356+
)}
357+
<div className="mt-1.5 flex items-center justify-end gap-2">
358+
<div className="flex items-center gap-1.5 opacity-0 transition-opacity duration-200 focus-within:opacity-100 group-hover:opacity-100">
359+
{displayedUserMessage.copyText && (
360+
<MessageCopyButton text={displayedUserMessage.copyText} />
361+
)}
362+
{canRevertAgentWork && (
363+
<Button
364+
type="button"
365+
size="xs"
366+
variant="outline"
367+
disabled={ctx.isRevertingCheckpoint || ctx.isWorking}
368+
onClick={() => ctx.onRevertUserMessage(row.message.id)}
369+
title="Revert to this message"
370+
>
371+
<Undo2Icon className="size-3" />
372+
</Button>
373+
)}
374+
</div>
375+
<p className="text-right text-chat-xs text-muted-foreground/50">
376+
{formatTimestamp(row.message.createdAt, ctx.timestampFormat)}
377+
</p>
372378
</div>
373-
<p className="text-right text-chat-xs text-muted-foreground/50">
374-
{formatTimestamp(row.message.createdAt, ctx.timestampFormat)}
375-
</p>
376379
</div>
377-
</UserMessageBubbleShell>
380+
</div>
378381
);
379382
})()}
380383

@@ -403,7 +406,7 @@ function TimelineRowContent({ row }: { row: TimelineRow }) {
403406
<span className="h-px flex-1 bg-border" />
404407
</div>
405408
)}
406-
<AssistantMessageBubbleShell>
409+
<div className="min-w-0 px-1 py-0.5">
407410
<ChatMarkdown
408411
text={messageText}
409412
cwd={ctx.markdownCwd}
@@ -442,7 +445,7 @@ function TimelineRowContent({ row }: { row: TimelineRow }) {
442445
</div>
443446
) : null}
444447
</div>
445-
</AssistantMessageBubbleShell>
448+
</div>
446449
</>
447450
);
448451
})()}

‎apps/web/src/components/chat/chatBubbleShells.tsx‎

Lines changed: 0 additions & 82 deletions
This file was deleted.

‎apps/web/src/components/settings/ChatFontSizePreview.tsx‎

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,6 @@
11
import { SquarePenIcon, TerminalIcon } from "lucide-react";
2-
import { type ReactNode } from "react";
2+
import { type CSSProperties, type ReactNode } from "react";
33
import ChatMarkdown from "../ChatMarkdown";
4-
import {
5-
AssistantMessageBubbleShell,
6-
ChatFontSizeScope,
7-
UserMessageBubbleShell,
8-
} from "../chat/chatBubbleShells";
94

105
const SAMPLE_MARKDOWN = `Sure — here's the refactor:
116
@@ -35,29 +30,32 @@ interface ChatFontSizePreviewProps {
3530
* - `text-chat-xxs` — tool-row preview text
3631
* - `text-chat-xxxs` — changed-file chip, assistant meta line
3732
* - `text-chat-body` — user/assistant message bodies
38-
* Plus `ChatMarkdown`, whose `.chat-markdown` rules in `index.css` also
39-
* key off `--chat-font-size` via the `[data-timeline-root]` selector that
40-
* `ChatFontSizeScope` sets.
33+
* Plus `ChatMarkdown`, whose `.chat-markdown` rules in `index.css` scale
34+
* via `[data-timeline-root]` — set here on the wrapper along with
35+
* `--chat-font-size`, mirroring what MessagesTimeline does on its rows.
4136
*/
4237
export function ChatFontSizePreview({ fontSize }: ChatFontSizePreviewProps) {
4338
return (
44-
<ChatFontSizeScope
45-
fontSize={fontSize}
39+
<div
4640
aria-hidden
41+
data-timeline-root="true"
42+
style={{ "--chat-font-size": `${fontSize}px` } as CSSProperties}
4743
className="space-y-3 rounded-md border border-border/60 bg-muted/40 px-3 py-3"
4844
>
4945
<PreviewWorkLog />
50-
<UserMessageBubbleShell>
51-
<div className="whitespace-pre-wrap wrap-break-word text-chat-body leading-relaxed text-foreground">
52-
Can you refactor this function to use early returns?
46+
<div className="flex justify-end">
47+
<div className="relative max-w-[80%] rounded-2xl rounded-br-sm border border-border bg-secondary px-4 py-3">
48+
<div className="whitespace-pre-wrap wrap-break-word text-chat-body leading-relaxed text-foreground">
49+
Can you refactor this function to use early returns?
50+
</div>
51+
<p className="mt-1.5 text-right text-chat-xs text-muted-foreground/50">09:45</p>
5352
</div>
54-
<p className="mt-1.5 text-right text-chat-xs text-muted-foreground/50">09:45</p>
55-
</UserMessageBubbleShell>
56-
<AssistantMessageBubbleShell>
53+
</div>
54+
<div className="min-w-0 px-1 py-0.5">
5755
<ChatMarkdown text={SAMPLE_MARKDOWN} cwd={undefined} isStreaming={false} />
5856
<p className="mt-1.5 text-chat-xxxs text-muted-foreground/30">Just now • 1.2s</p>
59-
</AssistantMessageBubbleShell>
60-
</ChatFontSizeScope>
57+
</div>
58+
</div>
6159
);
6260
}
6361

0 commit comments

Comments
 (0)