TypeScript
fix(web): chat tables open at the right size instead of collapsed and cut off (#26449)
Theo Browneeb751fa0730d
diff --git a/apps/web/src/components/chat/MarkdownExternalLink.tsx b/apps/web/src/components/chat/MarkdownExternalLink.tsxindex b3efae29406..9b4618b8f3f 100644--- a/apps/web/src/components/chat/MarkdownExternalLink.tsx+++ b/apps/web/src/components/chat/MarkdownExternalLink.tsx@@ -54,13 +54,19 @@ function leadingExternalLinkTextLength(text: string): number {return Math.min(text.length, 1);}+// Long words such as URLs can break after any character so they fit narrow+// table columns. Short ones, like a PR number, stay whole.function breakableExternalLinkText(text: string): ReactNode[] {- return Array.from(text, (character, index) => (- <Fragment key={`${index}:${character}`}>- {character}- <wbr />- </Fragment>- ));+ return Array.from(text.matchAll(/\s+|\S+/g), ({ 0: word, index: start }) =>+ word.length <= 16+ ? word+ : Array.from(word, (character, offset) => (+ <Fragment key={`${start + offset}:${character}`}>+ {character}+ <wbr />+ </Fragment>+ )),+ );}export function MarkdownExternalLinkContent({diff --git a/apps/web/src/components/chat/MarkdownTable.tsx b/apps/web/src/components/chat/MarkdownTable.tsxindex 9859ff97ad5..ee1e1825adc 100644--- a/apps/web/src/components/chat/MarkdownTable.tsx+++ b/apps/web/src/components/chat/MarkdownTable.tsx@@ -1,8 +1,7 @@-import { Check, Copy, Maximize2, Minimize2 } from "lucide";-import { useRef, useState, type ComponentProps } from "react";+import { Check, Copy } from "lucide";+import { useRef, type ComponentProps } from "react";import { useCopyToClipboard } from "../../hooks/useCopyToClipboard";-import { getClientSettings } from "../../hooks/useSettings";import {serializeTableElementToCsv,serializeTableElementToMarkdown,@@ -16,13 +15,11 @@ import { reportMarkdownActionFailure } from "./markdownActionFailure";export function MarkdownTable({ children, ...props }: ComponentProps<"table">) {const containerRef = useRef<HTMLDivElement | null>(null);- const [expanded, setExpanded] = useState(() => getClientSettings().wordWrap);const { copyToClipboard, isCopied: copied } = useCopyToClipboard<"markdown" | "csv">({timeout: 1200,onError: (cause, format) =>reportMarkdownActionFailure({ operation: "copy-table", format }, cause),});- const expandLabel = expanded ? "Collapse table cells" : "Expand table cells";const copyLabel = copied ? "Copied" : "Copy table";const handleCopy = (format: "markdown" | "csv") => {@@ -37,33 +34,12 @@ export function MarkdownTable({ children, ...props }: ComponentProps<"table">) {};return (- <div- ref={containerRef}- className="chat-markdown-table-container"- data-expanded={expanded ? "true" : "false"}- >+ <div ref={containerRef} className="chat-markdown-table-container"><ScrollArea radius="none" chainVerticalScroll scrollFade className="w-full max-w-full"><table {...props}>{children}</table></ScrollArea>{/* Stays within the row's px-1: the chat lane clips sideways overflow. */}- <div className="mt-0.5 -mx-1 flex items-center justify-between select-none">- <Tooltip>- <TooltipTrigger- render={- <Button- type="button"- variant={expanded ? "secondary" : "ghost-muted"}- size="icon-xs"- aria-pressed={expanded}- onClick={() => setExpanded((value) => !value)}- aria-label={expandLabel}- />- }- >- <MorphIcon className="size-3" icon={expanded ? Minimize2 : Maximize2} />- </TooltipTrigger>- <TooltipPopup side="top">{expandLabel}</TooltipPopup>- </Tooltip>+ <div className="mt-0.5 -mx-1 flex items-center justify-end select-none"><Menu><Tooltip><TooltipTriggerdiff --git a/apps/web/src/components/chat/MessagesTimeline.tsx b/apps/web/src/components/chat/MessagesTimeline.tsxindex 8f830c3393c..a9cab1554a3 100644--- a/apps/web/src/components/chat/MessagesTimeline.tsx+++ b/apps/web/src/components/chat/MessagesTimeline.tsx@@ -1221,7 +1221,7 @@ const ConversationTimeline = memo(function ConversationTimeline({><divref={observeLaneWidth}- className="@container/chat-lane chat-content-lane overflow-x-clip"+ className="chat-content-lane overflow-x-clip"data-timeline-root="true"><AudioPreviewUnmountContext value={onAudioUnmount}>@@ -1241,10 +1241,7 @@ const ConversationTimeline = memo(function ConversationTimeline({{unmatchedPendingApprovals.size > 0 ? (<TimelineRowCtx value={sharedState}><div className="messages-timeline-row-frame">- <div- className="@container/chat-lane chat-content-lane overflow-x-clip"- data-timeline-root="true"- >+ <div className="chat-content-lane overflow-x-clip" data-timeline-root="true"><WorkLogBlock>{[...unmatchedPendingApprovals.values()].map((approval) => (<TimelinePendingApprovalRow key={approval.requestId} approval={approval} />diff --git a/apps/web/src/components/settings/TypographySettings.tsx b/apps/web/src/components/settings/TypographySettings.tsxindex a4380a3e0bd..9e3c58aea1c 100644--- a/apps/web/src/components/settings/TypographySettings.tsx+++ b/apps/web/src/components/settings/TypographySettings.tsx@@ -235,7 +235,7 @@ function WordWrapRow() {return (<SettingsRow{...searchableSetting("word-wrap")}- description="Wrap long lines in code blocks, tables, diffs, and file previews by default."+ description="Wrap long lines in code blocks, diffs, and file previews by default."resetAction={settings.wordWrap !== DEFAULT_UNIFIED_SETTINGS.wordWrap ? (<SettingResetButton@@ -248,7 +248,7 @@ function WordWrapRow() {<Switchchecked={settings.wordWrap}onCheckedChange={(checked) => updateSettings({ wordWrap: Boolean(checked) })}- aria-label="Wrap code, tables, diffs, and file previews by default"+ aria-label="Wrap code, diffs, and file previews by default"/>}/>diff --git a/apps/web/src/components/settings/settingsSearch.ts b/apps/web/src/components/settings/settingsSearch.tsindex 7a88a0ea9af..fe4faa61996 100644--- a/apps/web/src/components/settings/settingsSearch.ts+++ b/apps/web/src/components/settings/settingsSearch.ts@@ -380,7 +380,7 @@ export const SETTINGS_SEARCH_ITEMS = [id: "word-wrap",title: "Word wrap",to: "/settings/appearance",- searchTerms: ["long lines code blocks tables diffs file previews"],+ searchTerms: ["long lines code blocks diffs file previews"],},{id: "composer-context",diff --git a/apps/web/src/index.css b/apps/web/src/index.cssindex 67f28a89f71..8acc312321b 100644--- a/apps/web/src/index.css+++ b/apps/web/src/index.css@@ -2193,14 +2193,13 @@ code {}}-/* Diagnostics-style tables: row separators only, uppercase headers, and a- scroll-fade container for horizontal overflow. The root chat-markdown- wrapping rules (overflow-wrap: anywhere) would let columns shrink to single- characters and defeat the overflow — restore word-boundary wrapping so the- min column width is the longest word. */+/* Diagnostics-style tables: row separators only, and a scroll-fade container+ for horizontal overflow. Cells wrap and the table fits its lane. The root+ chat-markdown wrapping rules (overflow-wrap: anywhere) would let columns+ shrink to single characters, so restore word-boundary wrapping: the min+ column width is the longest word, and only wider content scrolls. */.chat-markdown table {width: 100%;- min-width: max-content;border-collapse: collapse;overflow-wrap: normal;word-break: normal;@@ -2230,48 +2229,21 @@ code {border-bottom: 1px solid color-mix(in srgb, var(--contrast-border) 60%, transparent);padding-block: 0.55rem;font-weight: 600;- white-space: nowrap;}.chat-markdown tbody td {border-bottom: 1px solid color-mix(in srgb, var(--contrast-border) 60%, transparent);}-/* Collapsed (default): single-line cells truncate so arbitrary chat content- cannot blow the column out; the footer toggle expands cells to wrap. */-.chat-markdown .chat-markdown-table-container[data-expanded="false"] th,-.chat-markdown .chat-markdown-table-container[data-expanded="false"] td {- overflow: hidden;+/* Caps a long path, URL, or chip at 24rem; text past the cap wraps. */+.chat-markdown :is(th, td) {max-width: 24rem;- text-overflow: ellipsis;- white-space: nowrap;-}--.chat-markdown .chat-markdown-table-container[data-expanded="true"] td {- max-width: 24rem;- overflow-wrap: anywhere;-}--/* Fit expanded tables to wide timeline lanes; narrow lanes keep horizontal- scrolling so prose columns remain readable. */-@container chat-lane (min-width: 36rem) {- .chat-markdown .chat-markdown-table-container[data-expanded="true"] table {- min-width: 0;- }-- .chat-markdown .chat-markdown-table-container[data-expanded="true"] th {- white-space: normal;- }-- .chat-markdown .chat-markdown-table-container[data-expanded="true"] td {- overflow-wrap: break-word;- }+ overflow-wrap: break-word;}/* Formula cells keep their natural width and scroll with the table. */-.chat-markdown .chat-markdown-table-container td:has([data-markdown-math]) {+.chat-markdown :is(th, td):has([data-markdown-math]) {max-width: none;- overflow: visible;}:root {