The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 22, 23:15 UTC
fix(web): wide chat tables fit the lane when cells wrap (#20878)
Co-authored-by: Julius Marminge <julius0216@outlook.com>
Mantas Kantautas committed
Oct 20, 2026 at 08:05 UTC
f8b06c5fd0b49a3873b15c4e6f21f7f916343172
4 files changed
+81
-26
apps/web/src/components/ChatMarkdown.browser.test.tsx
+60
@@ -7,6 +7,8 @@ import { createRoot, type Root } from "react-dom/client";
7
import { afterEach, beforeEach, describe, expect, it, vi } from "vite-plus/test";
8
import { page, userEvent } from "vite-plus/test/browser";
9
10
+import "../index.css";
11
+
12
import { filesystemEnvironment } from "../state/filesystem";
13
import { useRightPanelStore } from "../rightPanelStore";
14
import { getSyntaxHighlighterPromise } from "../lib/syntaxHighlighting";
@@ -129,6 +131,64 @@ function fileOptions(container: HTMLElement) {
131
.filter((label) => label?.startsWith("File options for "));
132
}
133
134
+describe("ChatMarkdown table layout", () => {
135
+ it.each([
136
+ { width: 36, timeline: true, fits: true },
137
+ { width: 48, timeline: true, fits: true },
138
+ { width: 35, timeline: true, fits: false },
139
+ { width: 48, timeline: false, fits: false },
140
+ ])(
141
+ "wraps expanded cells with fit=$fits in a $width rem container (timeline=$timeline)",
142
+ async ({ width, timeline, fits }) => {
143
+ const { container } = await render(
144
+ <div style={{ width: `${width}rem` }}>
145
+ <div className={timeline ? "@container/chat-lane chat-content-lane overflow-x-clip" : ""}>
146
+ <ChatMarkdown
147
+ cwd={undefined}
148
+ text={[
149
+ "| Change summary | Reason details | Verification status | Release impact | Followup actions |",
150
+ "| --- | --- | --- | --- | --- |",
151
+ "| Keep the complete explanation readable when the table is expanded in the conversation. | Allow each column to wrap its prose within the available space in the current chat lane. | Collapse and expand the table again to check that the text still fits and remains readable. | Keep the existing layout for narrow chat lanes and file previews. | Check the table again after resizing the conversation lane. |",
152
+ ].join("\n")}
153
+ />
154
+ </div>
155
+ </div>,
156
+ );
157
+ const table = container.querySelector("table")!;
158
+ const viewport = table.closest<HTMLElement>('[data-slot="scroll-area-viewport"]')!;
159
+ const cell = table.tBodies[0]!.rows[0]!.cells[0]!;
160
+ const collapse = () => buttonsLabelled(container, "Collapse table cells")[0];
161
+ if (collapse()) await act(async () => collapse()!.click());
162
+
163
+ const collapsedWidth = table.getBoundingClientRect().width;
164
+ const collapsedHeight = cell.getBoundingClientRect().height;
165
+ expect(viewport.clientWidth).toBeGreaterThan(0);
166
+ expect(viewport.scrollWidth).toBeGreaterThan(viewport.clientWidth);
167
+ expect(cell.scrollWidth).toBeGreaterThan(cell.clientWidth);
168
+
169
+ await act(async () => buttonsLabelled(container, "Expand table cells")[0]!.click());
170
+ const expandedWidth = table.getBoundingClientRect().width;
171
+ const expandedHeight = cell.getBoundingClientRect().height;
172
+ if (fits) {
173
+ expect(viewport.scrollWidth).toBeLessThanOrEqual(viewport.clientWidth + 1);
174
+ expect(expandedWidth).toBeLessThanOrEqual(viewport.clientWidth + 1);
175
+ } else {
176
+ expect(viewport.scrollWidth).toBeGreaterThan(viewport.clientWidth);
177
+ viewport.scrollLeft = 100;
178
+ expect(viewport.scrollLeft).toBeGreaterThan(0);
179
+ }
180
+ expect(expandedHeight).toBeGreaterThan(collapsedHeight);
181
+
182
+ await act(async () => collapse()!.click());
183
+ expect(table.getBoundingClientRect().width).toBeCloseTo(collapsedWidth, 0);
184
+ expect(cell.getBoundingClientRect().height).toBeCloseTo(collapsedHeight, 0);
185
+ await act(async () => buttonsLabelled(container, "Expand table cells")[0]!.click());
186
+ expect(table.getBoundingClientRect().width).toBeCloseTo(expandedWidth, 0);
187
+ expect(cell.getBoundingClientRect().height).toBeCloseTo(expandedHeight, 0);
188
+ },
189
+ );
190
+});
191
+
192
describe("ChatMarkdown bare anchor placeholders", () => {
193
it.each(["<A>", "<a>", "<a >", "<a/>", "<A/>", "<a />"])(
194
"preserves unmatched %s without linking later blocks",
apps/web/src/components/ChatMarkdown.tsx
+1
-25
@@ -639,30 +639,6 @@ function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
639
return observeResize(table, measureClippedCells);
640
}, [measureClippedCells]);
641
642
- function toggleExpanded() {
643
- const table = tableRef.current;
644
- if (!table) return;
645
-
646
- if (!expanded) {
647
- const rows = [...table.rows];
648
- const columnWidths = rows.reduce<number[]>((widths, row) => {
649
- [...row.cells].forEach((cell, columnIndex) => {
650
- widths[columnIndex] = Math.max(
651
- widths[columnIndex] ?? 0,
652
- cell.getBoundingClientRect().width,
653
- );
654
- });
655
- return widths;
656
- }, []);
657
-
658
- [...(table.tHead?.rows[0]?.cells ?? [])].forEach((cell, columnIndex) => {
659
- cell.style.minWidth = `${columnWidths[columnIndex] ?? cell.getBoundingClientRect().width}px`;
660
- });
661
- }
662
-
663
- setExpanded((value) => !value);
664
- }
665
-
642
const handleCopy = (format: "markdown" | "csv") => {
643
const table = containerRef.current?.querySelector("table");
644
if (!table || typeof navigator === "undefined" || navigator.clipboard == null) {
@@ -720,7 +696,7 @@ function MarkdownTable({ children, ...props }: React.ComponentProps<"table">) {
696
variant={expanded ? "secondary" : "ghost-muted"}
697
size="icon-xs"
698
aria-pressed={expanded}
723
- onClick={toggleExpanded}
699
+ onClick={() => setExpanded((value) => !value)}
700
aria-label={expandLabel}
701
/>
702
}
apps/web/src/components/chat/MessagesTimeline.tsx
+4
-1
@@ -1425,7 +1425,10 @@ const ConversationTimeline = memo(function ConversationTimeline({
1425
const renderItem = ({ item }: { item: MessagesTimelineRow }) => (
1426
<TimelineRowCtx value={sharedState}>
1427
<div className="messages-timeline-row-frame">
1428
- <div className="chat-content-lane overflow-x-clip" data-timeline-root="true">
1428
+ <div
1429
+ className="@container/chat-lane chat-content-lane overflow-x-clip"
1430
+ data-timeline-root="true"
1431
+ >
1432
<TimelineRowContent row={item} />
1433
</div>
1434
</div>
apps/web/src/index.css
+16
@@ -2147,6 +2147,22 @@ code {
2147
overflow-wrap: anywhere;
2148
}
2149
2150
+/* Fit expanded tables to wide timeline lanes; narrow lanes keep horizontal
2151
+ scrolling so prose columns remain readable. */
2152
+@container chat-lane (min-width: 36rem) {
2153
+ .chat-markdown .chat-markdown-table-container[data-expanded="true"] table {
2154
+ min-width: 0;
2155
+ }
2156
+
2157
+ .chat-markdown .chat-markdown-table-container[data-expanded="true"] th {
2158
+ white-space: normal;
2159
+ }
2160
+
2161
+ .chat-markdown .chat-markdown-table-container[data-expanded="true"] td {
2162
+ overflow-wrap: break-word;
2163
+ }
2164
+}
2165
+
2166
/* Formula cells keep their natural width and scroll with the table. */
2167
.chat-markdown .chat-markdown-table-container td:has([data-markdown-math]) {
2168
max-width: none;