From 0c3238c3ce3f66d8092b675299d64c9e92a3ceb7 Mon Sep 17 00:00:00 2001 From: 2SinceJuly <202121119+2SinceJuly@users.noreply.github.com> Date: Tue, 24 Nov 2026 02:30:04 +0800 Subject: [PATCH 1/2] fix(web): an unavailable work-log image keeps the 10rem strip instead of filling the row A viewed image whose file could not be read has no dimensions for authoredImageSizeStyle, so ChatMarkdownAssetImage passed only max-height: 10rem. The standalone frame is aspect-video w-full, so max-height alone left it free to take the thread column's full width and draw a 480x160 placeholder per missing thumbnail. Bound the unavailable frame to the cap in both axes so it stays inside the strip beside the loaded thumbnails. --- .../src/components/chat/ChatMarkdownMedia.tsx | 23 ++++++-- .../chat/MessagesTimeline.browser.test.tsx | 52 +++++++++++++++++-- 2 files changed, 66 insertions(+), 9 deletions(-) diff --git a/apps/web/src/components/chat/ChatMarkdownMedia.tsx b/apps/web/src/components/chat/ChatMarkdownMedia.tsx index ea8f5d224dd1..54648f1efc03 100644 --- a/apps/web/src/components/chat/ChatMarkdownMedia.tsx +++ b/apps/web/src/components/chat/ChatMarkdownMedia.tsx @@ -84,6 +84,16 @@ export function authoredImageSizeStyle( return undefined; } +/** + * A file whose bytes could not be read has no dimensions to size a box from, + * so a capped strip would draw it at whatever width its frame asks for. Bound + * it to the cap itself instead of leaving the frame free to fill the row. + */ +function unavailableImageSizeStyle(maxHeightRem: number): CSSProperties | undefined { + if (maxHeightRem === 30) return undefined; + return { maxWidth: `min(100%, 30rem, ${maxHeightRem}rem)`, aspectRatio: "1 / 1" }; +} + const CHAT_MARKDOWN_WORKSPACE_IMAGE_CLASS_NAME = cn( CHAT_MARKDOWN_MEDIA_LAYOUT_CLASS_NAME, CHAT_MARKDOWN_MEDIA_FRAME_CLASS_NAME, @@ -438,13 +448,16 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props : fallbackSrc + (props.srcFragment ?? ""); const knownSize = assetUrl._tag === "Success" ? assetUrl.imageDimensions : undefined; const maxHeightRem = props.maxHeightRem ?? 30; + const unavailable = assetUrl._tag === "Failure" && fallbackSrc === undefined; const style = props.style ?? (knownSize ? authoredImageSizeStyle(knownSize.width, knownSize.height, maxHeightRem) - : maxHeightRem !== 30 - ? { maxHeight: `${maxHeightRem}rem` } - : undefined); + : unavailable + ? unavailableImageSizeStyle(maxHeightRem) + : maxHeightRem !== 30 + ? { maxHeight: `${maxHeightRem}rem` } + : undefined); const actionsSource = assetMediaActionsSource({ environmentId: props.environmentId, resource, @@ -460,7 +473,7 @@ export const ChatMarkdownAssetImage = memo(function ChatMarkdownAssetImage(props return ( ({ })) as never, })); -const stubbedAsset = vi.hoisted(() => ({ url: "" })); +const stubbedAsset = vi.hoisted(() => ({ url: "", failed: false })); vi.mock(import("~/assets/assetUrls"), async (original) => { const actual = await original(); return { ...actual, useAssetUrlState: ((...args: Parameters) => - stubbedAsset.url - ? { _tag: "Success", url: stubbedAsset.url } - : actual.useAssetUrlState(...args)) as typeof actual.useAssetUrlState, + stubbedAsset.failed + ? { _tag: "Failure" } + : stubbedAsset.url + ? { _tag: "Success", url: stubbedAsset.url } + : actual.useAssetUrlState(...args)) as typeof actual.useAssetUrlState, useAssetUrls: ((...args: Parameters) => stubbedAsset.url ? args[1].map(() => stubbedAsset.url) @@ -1842,6 +1844,48 @@ describe("MessagesTimeline attachments", () => { ); }); + it("keeps an unavailable viewed image inside the 10rem work-log strip", async () => { + stubbedAsset.failed = true; + onTestFinished(() => { + stubbedAsset.failed = false; + }); + await using screen = await renderElement( + + + , + ); + const frame = await vi.waitFor(() => { + const element = screen.container.querySelector( + '[data-image-gallery] [role="alert"]', + ); + expect(element).toBeTruthy(); + return element!; + }); + // A missing file has no dimensions, so the frame must draw its own square + // cap instead of letting `aspect-video w-full` fill the thread column. + const size = await vi.waitFor(() => { + const rect = frame.getBoundingClientRect(); + expect(rect.width).toBeGreaterThan(0); + return rect; + }); + expect(size.width).toBeLessThanOrEqual(161); + expect(Math.abs(size.width - size.height)).toBeLessThanOrEqual(1); + }); + it("opens an image from an expanded tool row as a gallery of the turn's viewed images", async () => { stubbedAsset.url = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII="; From 0e12293581a308a051998e60cadf1a0aab389dae Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 18:45:36 +0000 Subject: [PATCH 2/2] fix(web): keep the unavailable placeholder 16:9 at the strip's height cap The frame is aspect-video; a square changed its shape beyond the fix. Co-Authored-By: Claude Opus 5.5 --- apps/web/src/components/chat/ChatMarkdownMedia.tsx | 8 ++++---- .../src/components/chat/MessagesTimeline.browser.test.tsx | 7 +++---- 2 files changed, 7 insertions(+), 8 deletions(-) diff --git a/apps/web/src/components/chat/ChatMarkdownMedia.tsx b/apps/web/src/components/chat/ChatMarkdownMedia.tsx index 54648f1efc03..1bf15380c121 100644 --- a/apps/web/src/components/chat/ChatMarkdownMedia.tsx +++ b/apps/web/src/components/chat/ChatMarkdownMedia.tsx @@ -85,13 +85,13 @@ export function authoredImageSizeStyle( } /** - * A file whose bytes could not be read has no dimensions to size a box from, - * so a capped strip would draw it at whatever width its frame asks for. Bound - * it to the cap itself instead of leaving the frame free to fill the row. + * An unavailable file has no dimensions, so its `aspect-video w-full` frame + * would fill the row and `max-height` would squash it. Bound the width so the + * frame stays 16:9 at the height cap. */ function unavailableImageSizeStyle(maxHeightRem: number): CSSProperties | undefined { if (maxHeightRem === 30) return undefined; - return { maxWidth: `min(100%, 30rem, ${maxHeightRem}rem)`, aspectRatio: "1 / 1" }; + return { maxWidth: `min(100%, 30rem, ${(maxHeightRem * 16) / 9}rem)` }; } const CHAT_MARKDOWN_WORKSPACE_IMAGE_CLASS_NAME = cn( diff --git a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx index 75bb742df9b7..379191d6e414 100644 --- a/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx +++ b/apps/web/src/components/chat/MessagesTimeline.browser.test.tsx @@ -1875,15 +1875,14 @@ describe("MessagesTimeline attachments", () => { expect(element).toBeTruthy(); return element!; }); - // A missing file has no dimensions, so the frame must draw its own square - // cap instead of letting `aspect-video w-full` fill the thread column. const size = await vi.waitFor(() => { const rect = frame.getBoundingClientRect(); expect(rect.width).toBeGreaterThan(0); return rect; }); - expect(size.width).toBeLessThanOrEqual(161); - expect(Math.abs(size.width - size.height)).toBeLessThanOrEqual(1); + expect(size.height).toBeLessThanOrEqual(161); + expect(size.width).toBeLessThanOrEqual(285); + expect(Math.abs(size.width / size.height - 16 / 9)).toBeLessThan(0.02); }); it("opens an image from an expanded tool row as a gallery of the turn's viewed images", async () => {