@devries-cameron20 / t3code Mirror · read-only / commits / 854247e242
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 22, 08:15 UTC

fix(web): expanded SVG diagrams fill the image viewer (#27519)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net>

Melbourne Baldove committed Nov 1, 2026 at 10:39 UTC 854247e2420a13d4e4dd2c649e60671f0bfb9631
4 files changed +60 -3
apps/web/src/components/ChatMarkdown.tsx
+6 -1
@@ -1614,7 +1614,12 @@ const CHAT_MARKDOWN_COMPONENTS = {
1614 fenceTitle={fenceTitle}
1615 theme={resolvedTheme}
1616 isStreaming={isStreaming && !isClosedCodeFence(node, text, codeBlock.code)}
1617 - onExpand={(src) => expandMedia({ images: [{ src, name: "Mermaid diagram" }], index: 0 })}
1617 + onExpand={(src) =>
1618 + expandMedia({
1619 + images: [{ src, name: "Mermaid diagram", mimeType: "image/svg+xml" }],
1620 + index: 0,
1621 + })
1622 + }
1623 >
1624 {highlightedCode}
1625 </MarkdownMermaidCodeBlock>
apps/web/src/components/chat/ExpandedImageDialog.browser.test.tsx
+39
@@ -16,7 +16,46 @@ const snapShotSource: SnapShotSource = {
16 windowTitle: "Downloads",
17 };
18
19 +const D2_SVG =
20 + '<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1174 920"><rect width="1174" height="920"/></svg>';
21 +
22 describe("ExpandedImageDialog", () => {
23 + it.each(["/work/pipeline.svg", "/work/diagram#v2.svg", "/work/diagram?v2.svg"])(
24 + "fits a markdown SVG without intrinsic size to the viewer: %s",
25 + async (path) => {
26 + const src = URL.createObjectURL(new Blob([D2_SVG], { type: "image/svg+xml" }));
27 + using _src = { [Symbol.dispose]: () => URL.revokeObjectURL(src) };
28 + await using screen = await render(
29 + <ExpandedImageDialog
30 + preview={{
31 + images: [
32 + {
33 + src,
34 + name: "Pipeline",
35 + actionsSource: {
36 + kind: "image",
37 + name: "Pipeline",
38 + src,
39 + reference: { kind: "file", path },
40 + },
41 + },
42 + ],
43 + index: 0,
44 + }}
45 + onClose={vi.fn()}
46 + />,
47 + // The dialog renders no links and reads no route.
48 + { router: false },
49 + );
50 +
51 + const viewer = screen.getByRole("region", { name: "Pipeline, zoomable image" });
52 + const availableWidth = window.innerWidth * 0.92 - (window.innerWidth >= 640 ? 96 : 0);
53 + await vi.waitFor(() =>
54 + expect(viewer.element().getBoundingClientRect().width).toBeCloseTo(availableWidth, 0),
55 + );
56 + },
57 + );
58 +
59 it("Escape closes a popup opened inside the dialog before the dialog", async () => {
60 const onClose = vi.fn();
61 await using screen = await render(
apps/web/src/components/chat/ExpandedImageDialog.tsx
+13 -1
@@ -25,6 +25,8 @@ import { Atom } from "effect/reactivity";
25 import { appAtomRegistry } from "~/rpc/atomRegistry";
26 import { expandedImageKey } from "./ExpandedImagePreview";
27 import { registerThreadOverlay } from "./threadOverlayRetention";
28 +import { mediaReferenceFileName } from "@t3tools/client-runtime/media-reference";
29 +import { mediaMimeType, mediaMimeTypeFromExtension } from "@t3tools/shared/mediaPreview";
30
31 interface ExpandedImageDialogProps {
32 preview: ExpandedImagePreview;
@@ -42,6 +44,16 @@ function ExpandedMediaFailure({ children }: { children: ReactNode }) {
44 );
45 }
46
47 +function itemMimeType(item: ExpandedImageItem): string | undefined {
48 + if (item.mimeType) return item.mimeType;
49 + const reference = item.actionsSource?.reference;
50 + const fileName = reference && mediaReferenceFileName(reference);
51 + if (fileName) {
52 + return mediaMimeTypeFromExtension(fileName.slice(fileName.lastIndexOf("."))) ?? undefined;
53 + }
54 + return mediaMimeType(item.src ?? "") ?? undefined;
55 +}
56 +
57 function ExpandedVideo({ item }: { readonly item: ExpandedImageItem }) {
58 const asset = item.actionsSource?.asset;
59 const assetUrl = useAssetUrlState(asset?.environmentId ?? null, asset?.resource ?? null);
@@ -222,7 +234,7 @@ export const ExpandedImageDialog = memo(function ExpandedImageDialog({
234 key={`${index}:${item.src}`}
235 src={item.src}
236 name={item.name}
225 - mimeType={item.mimeType}
237 + mimeType={itemMimeType(item)}
238 onError={() => setFailedImageSrc(item.src)}
239 />
240 )}
apps/web/src/components/chat/ZoomableImage.tsx
+2 -1
@@ -71,8 +71,9 @@ export function ZoomableImage({
71 const suppressClickRef = useRef(false);
72 const [dragging, setDragging] = useState(false);
73 const maxHeight = Math.max(1, Math.min(viewerSize.height * 0.86, viewerSize.height - 160));
74 + // A vector scales without loss, and an SVG without width and height reports a tiny default size.
75 const fit = Math.min(
75 - 1,
76 + mimeType === "image/svg+xml" ? Infinity : 1,
77 (viewerSize.width * 0.92 - (viewerSize.width >= 640 ? 96 : 0)) / (naturalSize.width || 1),
78 maxHeight / (naturalSize.height || 1),
79 );