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 24, 14:00 UTC
fix(web): open agent images in expanded preview (#8807)
Co-authored-by: maria-rcks <254055478+maria-rcks@users.noreply.github.com>
maria committed
Aug 30, 2026 at 17:48 UTC
8f525af5afa93dff58775030d9b503d3bda36b7b
2 files changed
+51
-6
apps/web/src/components/ChatMarkdown.tsx
+50
-6
@@ -35,6 +35,7 @@ import React, {
35
Suspense,
36
type CSSProperties,
37
type ClipboardEvent as ReactClipboardEvent,
38
+ type KeyboardEvent as ReactKeyboardEvent,
39
type MouseEvent as ReactMouseEvent,
40
isValidElement,
41
use,
@@ -55,6 +56,7 @@ import remarkBreaks from "remark-breaks";
56
import remarkGfm from "remark-gfm";
57
import { remarkGithubAlerts } from "../markdown-github-alerts";
58
import { renderSkillInlineMarkdownChildren } from "./chat/SkillInlineText";
59
+import { type ExpandedImagePreview } from "./chat/ExpandedImagePreview";
60
import { CHAT_FILE_TAG_CHIP_CLASS_NAME, FileTagChipContent } from "./chat/FileTagChip";
61
import { PierreEntryIcon } from "./chat/PierreEntryIcon";
62
import {
@@ -155,6 +157,7 @@ interface ChatMarkdownProps {
157
/** Parse sanitized raw HTML instead of displaying its source text. */
158
parseRawHtml?: boolean;
159
imageBaseDir?: string | undefined;
160
+ onImageExpand?: ((preview: ExpandedImagePreview) => void) | undefined;
161
}
162
163
export function canUseMarkdownFileShellActions(
@@ -1089,6 +1092,31 @@ const CHAT_MARKDOWN_WORKSPACE_IMAGE_CLASS_NAME = cn(
1092
CHAT_MARKDOWN_WORKSPACE_IMAGE_LAYOUT_CLASS_NAME,
1093
"rounded-lg border border-border/40",
1094
);
1095
+const MarkdownLinkContext = React.createContext(false);
1096
+
1097
+function expandableMarkdownImageProps(
1098
+ onImageExpand: ((preview: ExpandedImagePreview) => void) | undefined,
1099
+ src: string,
1100
+ alt: string,
1101
+) {
1102
+ if (!onImageExpand) return {};
1103
+ const previewName = alt.trim() || "image";
1104
+ const expand = (event: ReactMouseEvent | ReactKeyboardEvent) => {
1105
+ if (event.currentTarget.closest("a")) return;
1106
+ event.preventDefault();
1107
+ event.stopPropagation();
1108
+ onImageExpand({ images: [{ src, name: previewName }], index: 0 });
1109
+ };
1110
+ return {
1111
+ role: "button" as const,
1112
+ tabIndex: 0,
1113
+ "aria-label": `Preview ${previewName}`,
1114
+ onClick: expand,
1115
+ onKeyDown: (event: ReactKeyboardEvent) => {
1116
+ if (event.key === "Enter" || event.key === " ") expand(event);
1117
+ },
1118
+ };
1119
+}
1120
1121
function ChatMarkdownImageFallback(props: {
1122
readonly alt: string;
@@ -1118,6 +1146,7 @@ const ChatMarkdownWorkspaceImage = memo(function ChatMarkdownWorkspaceImage(prop
1146
readonly copyMarkdown: string;
1147
readonly srcFragment: string;
1148
readonly style?: CSSProperties | undefined;
1149
+ readonly onImageExpand?: ((preview: ExpandedImagePreview) => void) | undefined;
1150
}) {
1151
const assetUrl = useAssetUrlState(props.threadRef.environmentId, {
1152
_tag: "workspace-file",
@@ -1144,15 +1173,20 @@ const ChatMarkdownWorkspaceImage = memo(function ChatMarkdownWorkspaceImage(prop
1173
/>
1174
);
1175
}
1176
+ const src = assetUrl.url + props.srcFragment;
1177
return (
1178
<img
1149
- src={assetUrl.url + props.srcFragment}
1179
+ src={src}
1180
alt={props.alt}
1181
data-markdown-copy={props.copyMarkdown}
1182
loading="lazy"
1183
draggable={false}
1154
- className={CHAT_MARKDOWN_WORKSPACE_IMAGE_CLASS_NAME}
1184
+ className={cn(
1185
+ CHAT_MARKDOWN_WORKSPACE_IMAGE_CLASS_NAME,
1186
+ props.onImageExpand && "cursor-zoom-in",
1187
+ )}
1188
style={props.style}
1189
+ {...expandableMarkdownImageProps(props.onImageExpand, src, props.alt)}
1190
onError={() => setFailedUrl(assetUrl.url)}
1191
/>
1192
);
@@ -1694,6 +1728,7 @@ function ChatMarkdown({
1728
lineBreaks = false,
1729
parseRawHtml = true,
1730
imageBaseDir,
1731
+ onImageExpand,
1732
}: ChatMarkdownProps) {
1733
const { resolvedTheme } = useTheme();
1734
const createAssetUrl = useAtomQueryRunner(assetEnvironment.createUrl, {
@@ -2084,6 +2119,7 @@ function ChatMarkdown({
2119
const isSameDocumentLink = href?.startsWith("#") ?? false;
2120
const onClick = props.onClick;
2121
const canOpenInPreview = Boolean(threadRef) && isPreviewSupportedInRuntime();
2122
+ const linkChildren = <MarkdownLinkContext value>{children}</MarkdownLinkContext>;
2123
const link = (
2124
<a
2125
{...props}
@@ -2160,10 +2196,10 @@ function ChatMarkdown({
2196
>
2197
{faviconHost && hastHasText(node) ? (
2198
<MarkdownExternalLinkContent host={faviconHost} plainText={plainHastText(node)}>
2163
- {children}
2199
+ {linkChildren}
2200
</MarkdownExternalLinkContent>
2201
) : (
2166
- children
2202
+ linkChildren
2203
)}
2204
</a>
2205
);
@@ -2205,7 +2241,8 @@ function ChatMarkdown({
2241
</code>
2242
);
2243
},
2208
- img({ node, title, src, alt, ...props }) {
2244
+ img: function MarkdownImage({ node, title, src, alt, ...props }) {
2245
+ const imageExpand = use(MarkdownLinkContext) ? undefined : onImageExpand;
2246
const localSrc = node?.properties?.dataLocalSrc;
2247
const markdownTitle = node?.properties?.dataMarkdownTitle;
2248
const authoredSrc = typeof localSrc === "string" ? localSrc : src;
@@ -2225,8 +2262,13 @@ function ChatMarkdown({
2262
src={imageSource.uri}
2263
alt={altText}
2264
loading="lazy"
2228
- className={cn(props.className, CHAT_MARKDOWN_IMAGE_SIZE_CLASS_NAME)}
2265
+ className={cn(
2266
+ props.className,
2267
+ CHAT_MARKDOWN_IMAGE_SIZE_CLASS_NAME,
2268
+ imageExpand && "cursor-zoom-in",
2269
+ )}
2270
style={authoredSizeStyle}
2271
+ {...expandableMarkdownImageProps(imageExpand, imageSource.uri, altText)}
2272
/>
2273
);
2274
}
@@ -2239,6 +2281,7 @@ function ChatMarkdown({
2281
copyMarkdown={copyMarkdown}
2282
srcFragment={markdownImageSourceFragment(classifiedSrc)}
2283
style={authoredSizeStyle}
2284
+ onImageExpand={imageExpand}
2285
/>
2286
);
2287
}
@@ -2289,6 +2332,7 @@ function ChatMarkdown({
2332
isStreaming,
2333
markdownFileLinkMetaByHref,
2334
onTaskListChange,
2335
+ onImageExpand,
2336
openFileInPanel,
2337
openInPreferredEditor,
2338
openChangeRequestLink,
apps/web/src/components/chat/MessagesTimeline.tsx
+1
@@ -1253,6 +1253,7 @@ function AssistantTimelineRow({ row }: { row: Extract<TimelineRow, { kind: "mess
1253
isStreaming={Boolean(row.message.streaming)}
1254
lineBreaks={shouldPreserveAssistantLineBreaks(messageText)}
1255
skills={ctx.skills}
1256
+ onImageExpand={ctx.onImageExpand}
1257
/>
1258
<AssistantChangedFilesSection
1259
turnSummary={row.assistantTurnDiffSummary}