@devries-cameron20 / t3code Mirror · read-only / commits / a9f2d7d5f4
Fork 0

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 21, 22:15 UTC

fix(web): "Show full message" only appears when it at least doubles the message (#34306)

Co-authored-by: Claude Fable 5.2 <noreply@anthropic.com>

Theo Browne committed Nov 11, 2026 at 13:42 UTC a9f2d7d5f4bd9191daa114b0a55d7b6bdda3484a
6 files changed +65 -69
apps/web/src/components/chat/MessagesTimeline.browser.test.tsx
+19
@@ -487,6 +487,25 @@ describe("MessagesTimeline messages", () => {
487 expect(maxNestedCommits).toBeLessThan(20);
488 });
489
490 + it("folds a user message only when the fold hides at least as much as it shows", async () => {
491 + setup();
492 + const lines = (count: number) =>
493 + Array.from({ length: count }, (_, index) => `Line ${index}`).join("\n");
494 + await using screen = await renderTimeline([
495 + message(lines(12), {}, "medium"),
496 + message(lines(60), {}, "long"),
497 + ]);
498 + await vi.waitFor(() => expect(screen.buttons("Show full message")).toHaveLength(1));
499 + const [medium, long] = [
500 + ...screen.container.querySelectorAll<HTMLElement>("[data-user-message-body]"),
501 + ];
502 + expect(medium!.dataset.userMessageCollapsible).toBe("false");
503 + expect(medium!.textContent).toContain("Line 11");
504 + const foldedHeight = long!.offsetHeight;
505 + await click(screen.button("Show full message"));
506 + expect(long!.offsetHeight).toBeGreaterThanOrEqual(foldedHeight * 2);
507 + });
508 +
509 it("keeps the first and last message headings reachable from either end", async () => {
510 setup();
511 const props = baseProps();
apps/web/src/components/chat/MessagesTimeline.logic.test.ts
+1 -27
@@ -21,15 +21,13 @@ import {
21 import { makeStreamingTimelineFixture } from "../../test-fixtures";
22 import type { TurnDiffSummary } from "../../types";
23 import { describe, expect, it } from "vite-plus/test";
24 -import { EnvironmentId, MessageId, RunId } from "@t3tools/contracts";
25 -import { serializeAssistantCitation } from "@t3tools/shared/assistantCitations";
24 +import { MessageId, RunId } from "@t3tools/contracts";
25 import {
26 computeStableMessagesTimelineRows,
27 deriveMessagesTimelineRows,
28 timelineTurnFoldRunIdsByEntryId,
29 liveAnswerPreview,
30 deriveMessagesTimelineRowsWithState,
32 - shouldCollapseUserMessage,
31 resolveAssistantMessageCopyState,
32 type MessagesTimelineRow,
33 workEntryDisplayLabel,
@@ -4779,27 +4777,3 @@ describe("subagent continued by a later turn", () => {
4777 ]);
4778 });
4779 });
4782 -
4783 -describe("shouldCollapseUserMessage", () => {
4784 - it("measures a quote by its card, not its encoded link", () => {
4785 - const quote = "A long assistant paragraph that the user quoted. ".repeat(40);
4786 - const source = {
4787 - version: 1 as const,
4788 - environmentId: EnvironmentId.make("environment"),
4789 - threadId: ThreadId.make("thread"),
4790 - messageId: MessageId.make("source"),
4791 - text: quote,
4792 - start: 0,
4793 - end: quote.length,
4794 - prefix: "",
4795 - suffix: "",
4796 - };
4797 - const citation = serializeAssistantCitation({ ...source, comment: "Why does this matter?" });
4798 - const bare = serializeAssistantCitation(source);
4799 -
4800 - expect(shouldCollapseUserMessage(`${citation} Can you expand on this?`)).toBe(false);
4801 - expect(shouldCollapseUserMessage(`${citation} ${"More text. ".repeat(60)}`)).toBe(true);
4802 - expect(shouldCollapseUserMessage(bare.repeat(2))).toBe(false);
4803 - expect(shouldCollapseUserMessage(bare.repeat(10))).toBe(true);
4804 - });
4805 -});
apps/web/src/components/chat/MessagesTimeline.logic.ts
-30
@@ -3,7 +3,6 @@ import { worktreeSetupAgentStarted } from "@t3tools/client-runtime/worktree-setu
3 import { resolveUserMessagePresentation } from "@t3tools/client-runtime/user-message";
4 import { isLiveSubagentTurnItem } from "@t3tools/client-runtime/state/subagentRuntime";
5 import * as Equal from "effect/Equal";
6 -import { collectAssistantCitations } from "@t3tools/shared/assistantCitations";
6 import { shallow } from "zustand/vanilla/shallow";
7 import { claudeResumeCompactionAge } from "@t3tools/shared/claudeCompaction";
8 import {
@@ -2699,35 +2698,6 @@ function isRowUnchanged(a: MessagesTimelineRow, b: MessagesTimelineRow): boolean
2698 }
2699 }
2700
2702 -const MAX_COLLAPSED_USER_MESSAGE_LINES = 8;
2703 -const MAX_COLLAPSED_USER_MESSAGE_LENGTH = 600;
2704 -const MARKDOWN_LINK = /!?\[([^\]\n]*)\]\((?:<[^>\n]*>|[^\s)]*)\)/g;
2705 -
2706 -function visibleUserMessageText(text: string): string {
2707 - const linkLabels = (segment: string) => segment.replace(MARKDOWN_LINK, "$1");
2708 - let visible = "";
2709 - let cursor = 0;
2710 - for (const match of collectAssistantCitations(text)) {
2711 - // A quote shows as a two-line card, counted here as a mark, with its comment under it.
2712 - visible += linkLabels(text.slice(cursor, match.start));
2713 - visible += "\n\u275D\n" + (match.citation.comment ?? "") + "\n";
2714 - cursor = match.end;
2715 - }
2716 - return visible + linkLabels(text.slice(cursor));
2717 -}
2718 -
2719 -export function shouldCollapseUserMessage(text: string): boolean {
2720 - const visible = visibleUserMessageText(text);
2721 - if (visible.trim().length === 0) {
2722 - return false;
2723 - }
2724 -
2725 - return (
2726 - visible.length > MAX_COLLAPSED_USER_MESSAGE_LENGTH ||
2727 - visible.split("\n").length > MAX_COLLAPSED_USER_MESSAGE_LINES
2728 - );
2729 -}
2730 -
2701 export function handoffRunsSignature(runs: ReadonlyArray<HandoffTimelineRun>): string {
2702 return runs
2703 .map(
apps/web/src/components/chat/TimelineUserMessageRow.tsx
+12 -9
@@ -57,7 +57,6 @@ import { MessageCopyButton } from "./MessageCopyButton";
57 import { promptLinkFor } from "../promptLinks/copyPromptLink";
58 import { PierreEntryIcon } from "./PierreEntryIcon";
59 import { formatBytes } from "../../lib/formatBytes";
60 -import { shouldCollapseUserMessage } from "./MessagesTimeline.logic";
60 import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
61 import {
62 asKnownContextRecord,
@@ -80,6 +79,7 @@ import { markdownProseDirection } from "~/textDirection";
79 import { useMediaQuery } from "~/hooks/useMediaQuery";
80 import { formatChatTimestampTooltip, formatDayAwareTimestamp } from "../../timestampFormat";
81 import { WorkflowOpeningBlock } from "./WorkflowOpeningBlock";
82 +import { useTallEnoughToFold } from "./useTallEnoughToFold";
83 import { TimelineRowCtx, TimelineRowActivityCtx, type TimelineRow } from "./timelineRowContext";
84 import {
85 MESSAGE_HEADING_LEVEL,
@@ -1130,8 +1130,9 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop
1130 const revealForFind = () => setExpanded(true);
1131 const revealRef = findRevealRef(revealForFind);
1132 const hasVisibleBody = props.text.trim().length > 0;
1133 - const canCollapse =
1134 - props.collapsible !== false && hasVisibleBody && shouldCollapseUserMessage(props.text);
1133 + const { ref: contentRef, tallEnough: canCollapse } = useTallEnoughToFold(
1134 + props.collapsible !== false && hasVisibleBody,
1135 + );
1136 const isCollapsed = canCollapse && !expanded;
1137 const showCollapseControl = canCollapse;
1138
@@ -1156,12 +1157,14 @@ const CollapsibleUserMessageBody = memo(function CollapsibleUserMessageBody(prop
1157 : undefined
1158 }
1159 >
1159 - <UserMessageBody
1160 - text={props.text}
1161 - renderContextReference={props.renderContextReference}
1162 - skills={props.skills}
1163 - markdownCwd={props.markdownCwd}
1164 - />
1160 + <div ref={contentRef}>
1161 + <UserMessageBody
1162 + text={props.text}
1163 + renderContextReference={props.renderContextReference}
1164 + skills={props.skills}
1165 + markdownCwd={props.markdownCwd}
1166 + />
1167 + </div>
1168 </div>
1169 ) : null}
1170 {showCollapseControl ? (
apps/web/src/components/chat/WorkflowOpeningBlock.tsx
+5 -3
@@ -23,7 +23,7 @@ import { Button } from "../ui/button";
23 import { Tooltip, TooltipTrigger } from "../ui/tooltip";
24 import { AgentElapsed } from "./AgentElapsed";
25 import { findRevealRef } from "./markdownFindContext";
26 -import { shouldCollapseUserMessage } from "./MessagesTimeline.logic";
26 +import { useTallEnoughToFold } from "./useTallEnoughToFold";
27 import { SubagentTooltipContent } from "./SubagentTooltipContent";
28 import { EnvironmentSubagentAvatar } from "./V2LifecycleRow";
29
@@ -204,7 +204,7 @@ function WorkflowMemberRow(props: {
204 function WorkflowScript(props: { readonly script: string }) {
205 const [expanded, setExpanded] = useState(false);
206 const revealRef = findRevealRef(() => setExpanded(true));
207 - const canFold = shouldCollapseUserMessage(props.script);
207 + const { ref: contentRef, tallEnough: canFold } = useTallEnoughToFold();
208 const folded = canFold && !expanded;
209 return (
210 <div>
@@ -219,7 +219,9 @@ function WorkflowScript(props: { readonly script: string }) {
219 : undefined
220 }
221 >
222 - <ChatMarkdown text={scriptMarkdown(props.script)} cwd={undefined} />
222 + <div ref={contentRef}>
223 + <ChatMarkdown text={scriptMarkdown(props.script)} cwd={undefined} />
224 + </div>
225 </div>
226 {canFold ? (
227 <div className="-ms-1">
apps/web/src/components/chat/useTallEnoughToFold.ts new
+28
@@ -0,0 +1,28 @@
1 +import { useLayoutEffect, useRef, useState } from "react";
2 +
3 +import { observeResize } from "~/lib/observeResize";
4 +
5 +// The folds clip with `max-h-44`, which is 11rem.
6 +const FOLDED_HEIGHT_REM = 11;
7 +
8 +/**
9 + * Put `ref` on the unclipped content inside a fold. `tallEnough` is true when that content is at
10 + * least twice the folded height, so opening a fold always at least doubles what was on screen.
11 + */
12 +export function useTallEnoughToFold(enabled = true) {
13 + const ref = useRef<HTMLDivElement>(null);
14 + const [tallEnough, setTallEnough] = useState(false);
15 + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- the fold depends on the rendered height, which only the DOM knows
16 + useLayoutEffect(() => {
17 + const content = ref.current;
18 + if (!enabled || !content) return;
19 + const measure = () => {
20 + const remPx = Number.parseFloat(getComputedStyle(document.documentElement).fontSize) || 16;
21 + setTallEnough(content.offsetHeight >= FOLDED_HEIGHT_REM * 2 * remPx);
22 + };
23 + // Measured here too: waiting for the observer would paint one unfolded frame.
24 + measure();
25 + return observeResize(content, measure);
26 + }, [enabled]);
27 + return { ref, tallEnough: enabled && tallEnough };
28 +}