@devries-cameron20 / t3code-1 / commits / 16918b57d6
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

fix(web): table expand button only shows when a cell is cut off (#19782)

Co-authored-by: PR Batch Tester <agent@local.test> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

shivam committed Oct 18, 2026 at 04:44 UTC 16918b57d6754d6f145e9b6367c825aa31a740da
1 file changed +66 -17
apps/web/src/components/ChatMarkdown.tsx
+66 -17
@@ -206,6 +206,7 @@ import {
206 resolvePullRequestPreviewTarget,
207 useOpenChangeRequestLink,
208 } from "~/lib/openPullRequestLink";
209 +import { observeResize } from "~/lib/observeResize";
210 import { useOpenLink } from "../browser/useOpenLink";
211 import { writeTextToClipboard } from "../hooks/useCopyToClipboard";
212 import { isPreviewAvailableFor } from "../browser/previewRuntime";
@@ -535,15 +536,59 @@ function readInitialWordWrapSetting(): boolean {
536 return getClientSettings().wordWrap;
537 }
538
539 +/**
540 + * Whether any cell is clipped in the unwrapped layout. Only then does the wrap
541 + * toggle change anything, so short tables hide it. Measures with the container
542 + * briefly unwrapped and restores it before the browser paints.
543 + */
544 +function tableHasClippedCells(container: HTMLElement, table: HTMLTableElement): boolean {
545 + const viewport = table.closest<HTMLElement>('[data-slot="scroll-area-viewport"]');
546 + const scrollLeft = viewport?.scrollLeft ?? 0;
547 + const previous = container.dataset.expanded;
548 + container.dataset.expanded = "false";
549 + try {
550 + for (const row of table.rows) {
551 + for (const cell of row.cells) {
552 + if (cell.scrollWidth > cell.clientWidth) return true;
553 + }
554 + }
555 + return false;
556 + } finally {
557 + if (previous === undefined) delete container.dataset.expanded;
558 + else container.dataset.expanded = previous;
559 + // The unwrapped layout can be narrower and clamp a sideways scroll.
560 + if (viewport && scrollLeft > 0) viewport.scrollLeft = scrollLeft;
561 + }
562 +}
563 +
564 function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
565 const containerRef = useRef<HTMLDivElement | null>(null);
566 const tableRef = useRef<HTMLTableElement | null>(null);
567 const [expanded, setExpanded] = useState(readInitialWordWrapSetting);
568 + const [hasClippedCells, setHasClippedCells] = useState(false);
569 const [copied, setCopied] = useState(false);
570 const copiedTimerRef = useRef<ReturnType<typeof setTimeout> | null>(null);
571 const expandLabel = expanded ? "Collapse table cells" : "Expand table cells";
572 const copyLabel = copied ? "Copied" : "Copy table";
573
574 + const measureClippedCells = () => {
575 + const container = containerRef.current;
576 + const table = tableRef.current;
577 + if (!container || !table) return;
578 + setHasClippedCells(tableHasClippedCells(container, table));
579 + };
580 +
581 + // A streamed cell can grow until it clips while the table keeps its size,
582 + // so remeasure after every render, not only on resize.
583 + useLayoutEffect(measureClippedCells);
584 +
585 + // Column width changes can clip a cell without rendering this table.
586 + useLayoutEffect(() => {
587 + const table = tableRef.current;
588 + if (!table) return;
589 + return observeResize(table, measureClippedCells);
590 + }, [measureClippedCells]);
591 +
592 function toggleExpanded() {
593 const table = tableRef.current;
594 if (!table) return;
@@ -616,23 +661,27 @@ function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
661 </table>
662 </ScrollArea>
663 <div className="mt-0.5 flex items-center justify-between select-none">
619 - <Tooltip>
620 - <TooltipTrigger
621 - render={
622 - <Button
623 - type="button"
624 - variant={expanded ? "secondary" : "ghost-muted"}
625 - size="icon-xs"
626 - aria-pressed={expanded}
627 - onClick={toggleExpanded}
628 - aria-label={expandLabel}
629 - />
630 - }
631 - >
632 - <MorphIcon className="size-3" icon={expanded ? Minimize2 : Maximize2} />
633 - </TooltipTrigger>
634 - <TooltipPopup side="top">{expandLabel}</TooltipPopup>
635 - </Tooltip>
664 + {hasClippedCells ? (
665 + <Tooltip>
666 + <TooltipTrigger
667 + render={
668 + <Button
669 + type="button"
670 + variant={expanded ? "secondary" : "ghost-muted"}
671 + size="icon-xs"
672 + aria-pressed={expanded}
673 + onClick={toggleExpanded}
674 + aria-label={expandLabel}
675 + />
676 + }
677 + >
678 + <MorphIcon className="size-3" icon={expanded ? Minimize2 : Maximize2} />
679 + </TooltipTrigger>
680 + <TooltipPopup side="top">{expandLabel}</TooltipPopup>
681 + </Tooltip>
682 + ) : (
683 + <span />
684 + )}
685 <Menu>
686 <Tooltip>
687 <TooltipTrigger