From bf0096b49db22495853688a6cea1d0b9a82e36d7 Mon Sep 17 00:00:00 2001 From: axb Date: Tue, 21 Jul 2026 17:02:47 +0800 Subject: [PATCH 1/2] fix(wework): enlarge generated image previews --- .../src/components/chat/MessageList.test.tsx | 24 ++++++-- wework/src/components/chat/MessageList.tsx | 57 +++++++++++++++++-- 2 files changed, 71 insertions(+), 10 deletions(-) diff --git a/wework/src/components/chat/MessageList.test.tsx b/wework/src/components/chat/MessageList.test.tsx index a9c570cc48d..b505d022132 100644 --- a/wework/src/components/chat/MessageList.test.tsx +++ b/wework/src/components/chat/MessageList.test.tsx @@ -145,7 +145,7 @@ describe('MessageList', () => { expect(await screen.findByTestId('message-selection-actions')).toBeInTheDocument() }) - test('renders generated image artifacts from image generation blocks', () => { + test('renders generated image artifacts and opens an enlarged preview', async () => { render( { toolName: 'image_generation', renderPayload: { kind: 'image_generation', - imageBase64: 'aW1hZ2U=', + imageBase64: + 'iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAF/gL+XwY7WQAAAABJRU5ErkJggg==', revisedPrompt: 'Minimal dashboard concept', }, status: 'done', @@ -175,9 +176,24 @@ describe('MessageList', () => { /> ) - const image = screen.getByTestId('generated-image') - expect(image).toHaveAttribute('src', 'data:image/png;base64,aW1hZ2U=') + const image = await screen.findByTestId('generated-image') + expect(image).toHaveAttribute( + 'src', + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAF/gL+XwY7WQAAAABJRU5ErkJggg==' + ) expect(image).toHaveAttribute('alt', 'Minimal dashboard concept') + + await userEvent.click(screen.getByTestId('generated-image-preview-button')) + + expect(await screen.findByTestId('attachment-image-lightbox')).toBeInTheDocument() + expect(await screen.findByTestId('attachment-image-lightbox-image')).toHaveAttribute( + 'src', + 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mNk+M/wHwAF/gL+XwY7WQAAAABJRU5ErkJggg==' + ) + expect(screen.getByTestId('attachment-image-lightbox-image')).toHaveAttribute( + 'alt', + 'Minimal dashboard concept' + ) }) test('marks message rows for offscreen rendering containment with intrinsic sizes', () => { diff --git a/wework/src/components/chat/MessageList.tsx b/wework/src/components/chat/MessageList.tsx index e14343ee5d9..375ce87810b 100644 --- a/wework/src/components/chat/MessageList.tsx +++ b/wework/src/components/chat/MessageList.tsx @@ -1823,6 +1823,19 @@ interface GeneratedImageArtifact { alt: string } +function generatedImageAttachment(image: GeneratedImageArtifact, index: number): Attachment { + return { + id: index + 1, + filename: image.alt, + file_size: 0, + mime_type: 'image/png', + status: 'ready', + file_extension: '.png', + created_at: '', + local_preview_url: image.src, + } +} + function getGeneratedImages(blocks: ProcessingBlock[]): GeneratedImageArtifact[] { return blocks.flatMap(block => { if (block.type !== 'tool' || block.toolName !== 'image_generation') return [] @@ -1845,24 +1858,56 @@ function getGeneratedImages(blocks: ProcessingBlock[]): GeneratedImageArtifact[] } function GeneratedImageGallery({ images }: { images: GeneratedImageArtifact[] }) { + const attachments = images.map(generatedImageAttachment) + return (
- {images.map(image => ( - ( + ))}
) } +function GeneratedImagePreview({ + image, + index, + galleryAttachments, +}: { + image: GeneratedImageArtifact + index: number + galleryAttachments: Attachment[] +}) { + const { id, src, alt } = image + const attachment = useMemo( + () => generatedImageAttachment({ id, src, alt }, index), + [alt, id, index, src] + ) + + return ( + + ) +} + function ContentTruncatedNotice({ originalChars, onLoadFullTranscript, From 8eece17b536f2b67f23e9d697dcf778daefc1d6c Mon Sep 17 00:00:00 2001 From: axb Date: Tue, 21 Jul 2026 17:33:56 +0800 Subject: [PATCH 2/2] fix(wework): stabilize generated image gallery --- .../src/components/chat/MessageList.test.tsx | 7 ++++++ wework/src/components/chat/MessageList.tsx | 24 +++++++------------ 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/wework/src/components/chat/MessageList.test.tsx b/wework/src/components/chat/MessageList.test.tsx index b505d022132..1c788e12f70 100644 --- a/wework/src/components/chat/MessageList.test.tsx +++ b/wework/src/components/chat/MessageList.test.tsx @@ -194,6 +194,13 @@ describe('MessageList', () => { 'alt', 'Minimal dashboard concept' ) + + await userEvent.click(screen.getByTestId('attachment-image-zoom-in')) + expect(screen.getByTestId('attachment-image-zoom-value')).toHaveTextContent('125%') + + fireEvent.pointerEnter(screen.getByTestId('message-hover-region')) + + expect(screen.getByTestId('attachment-image-zoom-value')).toHaveTextContent('125%') }) test('marks message rows for offscreen rendering containment with intrinsic sizes', () => { diff --git a/wework/src/components/chat/MessageList.tsx b/wework/src/components/chat/MessageList.tsx index 375ce87810b..a92407d0c98 100644 --- a/wework/src/components/chat/MessageList.tsx +++ b/wework/src/components/chat/MessageList.tsx @@ -1623,7 +1623,10 @@ function AssistantMessage({ const visibleContent = shouldHideContent ? '' : message.content const hiddenErrorContent = message.status === 'failed' && shouldHideContent ? message.content.trim() : undefined - const displayBlocks = getDisplayProcessingBlocks(message.blocks, isCancelled) + const displayBlocks = useMemo( + () => getDisplayProcessingBlocks(message.blocks, isCancelled), + [isCancelled, message.blocks] + ) const processingSegments = splitProcessingBlocks(displayBlocks) const hasBlocks = displayBlocks.length > 0 const hasVisibleContent = Boolean(visibleContent.trim()) @@ -1654,7 +1657,7 @@ function AssistantMessage({ ? [] : getWebSearchSourceItems(getWebSearchToolBlocks(displayBlocks)) const memoryCitations = message.memoryCitations ?? [] - const generatedImages = getGeneratedImages(displayBlocks) + const generatedImages = useMemo(() => getGeneratedImages(displayBlocks), [displayBlocks]) const [areHoverActionsVisible, setAreHoverActionsVisible] = useState(false) const openFileFromLink = (path: string, options?: WorkspaceFileOpenOptions) => { @@ -1858,7 +1861,7 @@ function getGeneratedImages(blocks: ProcessingBlock[]): GeneratedImageArtifact[] } function GeneratedImageGallery({ images }: { images: GeneratedImageArtifact[] }) { - const attachments = images.map(generatedImageAttachment) + const attachments = useMemo(() => images.map(generatedImageAttachment), [images]) return (
{images.map((image, index) => ( - + ))}
) } function GeneratedImagePreview({ - image, index, galleryAttachments, }: { - image: GeneratedImageArtifact index: number galleryAttachments: Attachment[] }) { - const { id, src, alt } = image - const attachment = useMemo( - () => generatedImageAttachment({ id, src, alt }, index), - [alt, id, index, src] - ) + const attachment = galleryAttachments[index] return (