Enhanced ChatGPT Clone: Features Agents, MCP, Skills, DeepSeek, Anthropic, AWS, OpenAI, Responses API, Azure, Groq, o1, GPT-5, Mistral, OpenRouter, Vertex AI, Gemini, Artifacts, AI model switching, message search, Code Interpreter, langchain, DALL-E-3, OpenAPI Actions, Functions, Secure Multi-User Auth, Presets, open-source for self-hosting. Active
TypeScript aianthropicartifactsawsazurechatgptchatgpt-cloneclaudeclonedeepseekgeminigooglegpt-5librechatmcpo1openairesponses-apivisionwebui
🫸 fix: Right-Align User Message Images (#16404)
lia-by-librechat[bot]b04226eb3ffe
diff --git a/client/src/components/Chat/Messages/Content/Files.tsx b/client/src/components/Chat/Messages/Content/Files.tsxindex 0f2be00c35..f5deee31f6 100644--- a/client/src/components/Chat/Messages/Content/Files.tsx+++ b/client/src/components/Chat/Messages/Content/Files.tsx@@ -43,6 +43,7 @@ const Files = ({ message }: { message?: TMessage }) => {imageFiles.map((file) => (<Imagekey={file.file_id}+ alignRightimagePath={file.preview ?? file.filepath ?? ''}height={file.height ?? 1920}width={file.width ?? 1080}diff --git a/client/src/components/Chat/Messages/Content/Image.tsx b/client/src/components/Chat/Messages/Content/Image.tsxindex 7e44b2e828..2c31783878 100644--- a/client/src/components/Chat/Messages/Content/Image.tsx+++ b/client/src/components/Chat/Messages/Content/Image.tsx@@ -28,6 +28,7 @@ const Image = ({imagePath,altText,className,+ alignRight = false,args,width,height,@@ -35,6 +36,7 @@ const Image = ({imagePath: string;altText: string;className?: string;+ alignRight?: boolean;args?: {prompt?: string;quality?: 'low' | 'medium' | 'high';@@ -94,7 +96,7 @@ const Image = ({const showSkeleton = hasDimensions && !paintedUrls.has(absoluteImageUrl);return (- <div>+ <div className={alignRight ? 'ml-auto' : undefined}><buttonref={triggerRef}type="button"diff --git a/client/src/components/Chat/Messages/Content/Part.tsx b/client/src/components/Chat/Messages/Content/Part.tsxindex 59e0625503..21500f0b5e 100644--- a/client/src/components/Chat/Messages/Content/Part.tsx+++ b/client/src/components/Chat/Messages/Content/Part.tsx@@ -559,6 +559,7 @@ const Part = memo(function Part({<ImageimagePath={cached ?? imageFile.filepath}altText={imageFile.filename ?? 'Uploaded Image'}+ alignRight={isCreatedByUser}width={imageFile.width}height={imageFile.height}/>diff --git a/client/src/components/Chat/Messages/Content/Parts/SteerPart.tsx b/client/src/components/Chat/Messages/Content/Parts/SteerPart.tsxindex f00ae091c7..ffd47c0bdb 100644--- a/client/src/components/Chat/Messages/Content/Parts/SteerPart.tsx+++ b/client/src/components/Chat/Messages/Content/Parts/SteerPart.tsx@@ -126,7 +126,7 @@ const SteerPart = memo(function SteerPart({<div className="flex max-w-full flex-col items-start gap-2 rounded-theme-surface rounded-br-theme-control bg-surface-tertiary px-theme-normal py-2.5"><MessageQuotes quotes={quotes} />{(imageFiles.length > 0 || otherFiles.length > 0) && (- <div className="flex flex-wrap gap-2">+ <div className="flex w-full flex-wrap gap-2">{otherFiles.map((file) => (<FileContainerkey={file.file_id}@@ -134,15 +134,19 @@ const SteerPart = memo(function SteerPart({onClick={() => setSelectedFile(file)}/>))}- {imageFiles.map((file) => (- <Image- key={file.file_id}- imagePath={file.preview ?? file.filepath ?? ''}- height={file.height ?? 1920}- width={file.width ?? 1080}- altText={file.filename ?? localize('com_ui_attached_image')}- />- ))}+ {imageFiles.length > 0 && (+ <div className="ml-auto flex max-w-full flex-wrap justify-end gap-2">+ {imageFiles.map((file) => (+ <Image+ key={file.file_id}+ imagePath={file.preview ?? file.filepath ?? ''}+ height={file.height ?? 1920}+ width={file.width ?? 1080}+ altText={file.filename ?? localize('com_ui_attached_image')}+ />+ ))}+ </div>+ )}</div>)}<CollapsibleText enabled={collapseLongUserMessages}>diff --git a/client/src/components/Chat/Messages/Content/Parts/__tests__/SteerPart.test.tsx b/client/src/components/Chat/Messages/Content/Parts/__tests__/SteerPart.test.tsxindex bf6898c8c3..53e973ebe1 100644--- a/client/src/components/Chat/Messages/Content/Parts/__tests__/SteerPart.test.tsx+++ b/client/src/components/Chat/Messages/Content/Parts/__tests__/SteerPart.test.tsx@@ -179,13 +179,21 @@ describe('SteerPart presentation', () => {expect(part).not.toHaveClass('md:-ml-9', '-ml-9');});- it('renders steer attachments', () => {+ it('keeps multiple steer images together at the right while file chips stay at the start', () => {renderPart([{ file_id: 'f1', filename: 'notes.pdf', type: 'application/pdf' },{ file_id: 'f2', filename: 'shot.png', type: 'image/png', filepath: '/images/shot.png' },+ { file_id: 'f3', filename: 'second.png', type: 'image/png', filepath: '/images/second.png' },]);+ const images = screen.getAllByTestId('steer-image');+ const imageGroup = images[0].parentElement;++ expect(images).toHaveLength(2);+ expect(imageGroup).toContainElement(images[1]);+ expect(imageGroup).toHaveClass('ml-auto', 'flex-wrap', 'justify-end');+ expect(imageGroup?.parentElement).toHaveClass('w-full');+ expect(imageGroup).not.toContainElement(screen.getByTestId('steer-file'));expect(screen.getByTestId('steer-file')).toHaveTextContent('notes.pdf');- expect(screen.getByTestId('steer-image')).toBeInTheDocument();});it.each(['application/pdf', 'image/png'])(diff --git a/client/src/components/Chat/Messages/Content/__tests__/Files.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/Files.test.tsxindex 267ecda3db..08b36f767f 100644--- a/client/src/components/Chat/Messages/Content/__tests__/Files.test.tsx+++ b/client/src/components/Chat/Messages/Content/__tests__/Files.test.tsx@@ -13,7 +13,11 @@ jest.mock(() =>({ onClick }: { onClick: () => void }) => <button onClick={onClick}>file action</button>,);-jest.mock('../Image', () => () => <div>image preview</div>);+jest.mock('../Image', () => ({ alignRight }: { alignRight?: boolean }) => (+ <div data-testid="image-preview" data-aligned-right={String(alignRight)}>+ image preview+ </div>+));jest.mock('../FilePreviewDialog',() =>@@ -35,6 +39,7 @@ it('exposes extracted image text without changing ordinary image previews', () =/>,);expect(screen.getAllByText('image preview')).toHaveLength(1);+ expect(screen.getByTestId('image-preview')).toHaveAttribute('data-aligned-right', 'true');fireEvent.click(screen.getByText('file action'));expect(screen.getByText('preview: text')).toBeInTheDocument();});diff --git a/client/src/components/Chat/Messages/Content/__tests__/Image.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/Image.test.tsxindex cef7093651..a06f5712bb 100644--- a/client/src/components/Chat/Messages/Content/__tests__/Image.test.tsx+++ b/client/src/components/Chat/Messages/Content/__tests__/Image.test.tsx@@ -114,6 +114,15 @@ describe('Image', () => {});describe('common behavior', () => {+ it('aligns only explicitly marked images to the right', () => {+ const { rerender } = render(<Image {...defaultProps} />);+ const wrapper = screen.getByRole('button').parentElement;+ expect(wrapper).not.toHaveClass('ml-auto');++ rerender(<Image {...defaultProps} alignRight />);+ expect(wrapper).toHaveClass('ml-auto');+ });+it('applies custom className to the button wrapper', () => {render(<Image {...defaultProps} className="mb-4" />);const button = screen.getByRole('button');diff --git a/client/src/components/Chat/Messages/Content/__tests__/Part.test.tsx b/client/src/components/Chat/Messages/Content/__tests__/Part.test.tsxindex f8be067fdc..bf6c75a6ad 100644--- a/client/src/components/Chat/Messages/Content/__tests__/Part.test.tsx+++ b/client/src/components/Chat/Messages/Content/__tests__/Part.test.tsx@@ -64,7 +64,9 @@ jest.mock('../ToolCall', () => ({jest.mock('../Image', () => ({__esModule: true,- default: () => <div data-testid="image" />,+ default: ({ alignRight }: { alignRight?: boolean }) => (+ <div data-testid="image" data-aligned-right={String(alignRight)} />+ ),}));jest.mock('~/utils', () => ({@@ -87,6 +89,26 @@ const toolCallPart = (name: string, args = '{"code":"echo hi"}'): TMessageConten},}) as unknown as TMessageContentParts;+describe('Part image alignment', () => {+ it('right-aligns user image parts without moving assistant images', () => {+ const imagePart = {+ type: ContentTypes.IMAGE_FILE,+ [ContentTypes.IMAGE_FILE]: {+ file_id: 'image-1',+ filename: 'upload.png',+ filepath: '/images/upload.png',+ },+ } as TMessageContentParts;+ const { rerender } = render(+ <Part part={imagePart} isSubmitting={false} showCursor={false} isCreatedByUser={false} />,+ );+ expect(screen.getByTestId('image')).toHaveAttribute('data-aligned-right', 'false');++ rerender(<Part part={imagePart} isSubmitting={false} showCursor={false} isCreatedByUser />);+ expect(screen.getByTestId('image')).toHaveAttribute('data-aligned-right', 'true');+ });+});+describe('Part tool renderer selection', () => {it.each(['image_gen_oai', 'image_edit_oai', 'gemini_image_gen'])('keeps a successful %s call on the image renderer',diff --git a/e2e/specs/mock/user-image-alignment.spec.ts b/e2e/specs/mock/user-image-alignment.spec.tsnew file mode 100644index 0000000000..6fa0160de7--- /dev/null+++ b/e2e/specs/mock/user-image-alignment.spec.ts@@ -0,0 +1,71 @@+import { expect, test } from '@playwright/test';+import { mkdirSync } from 'node:fs';+import path from 'node:path';+import {+ MOCK_ENDPOINTS,+ NEW_CHAT_PATH,+ messagesView,+ selectMockEndpoint,+ sendMessageAndWaitForCompletion,+} from './helpers';++const imageFixture = {+ name: 'upload.png',+ mimeType: 'image/png',+ buffer: Buffer.from(+ 'iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAACXBIWXMAAAPoAAAD6AG1e1JrAAAAHUlEQVQ4jWNwaDjwnxLMMGrA/9EwODAaBg3DIgwACY9/HwbtciYAAAAASUVORK5CYII=',+ 'base64',+ ),+};++const prompt =+ 'This image shows a background task in the conversation. Please describe the image layout and explain what the task is doing.';++test.use({ viewport: { width: 1280, height: 900 }, colorScheme: 'dark' });++test('keeps uploaded user images on the right side of a wider message bubble', async ({ page }) => {+ test.setTimeout(75_000);+ await page.addInitScript(() => localStorage.setItem('color-theme', 'dark'));+ await page.goto(NEW_CHAT_PATH);+ await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);++ await page.getByRole('button', { name: 'Attach File Options' }).click();+ const chooser = page.waitForEvent('filechooser');+ await page.getByText('Upload to Provider').click();+ const fileChooser = await chooser;+ const upload = page.waitForResponse(+ (response) =>+ new URL(response.url()).pathname === '/api/files/images' &&+ response.request().method() === 'POST' &&+ response.status() === 200,+ );+ await fileChooser.setFiles(imageFixture);+ expect((await upload).ok()).toBeTruthy();++ const response = await sendMessageAndWaitForCompletion(page, prompt);+ expect(response.ok()).toBeTruthy();++ const userTurn = messagesView(page).locator('.message-render').filter({ hasText: prompt }).last();+ await expect(userTurn.locator('.user-turn')).toBeVisible();+ const image = userTurn.getByRole('img', { name: imageFixture.name });+ await expect(image).toBeVisible();+ await image.evaluate(async (element) => (element as HTMLImageElement).decode());++ const captureDir = process.env.E2E_CAPTURE_DIR;+ if (captureDir) {+ mkdirSync(captureDir, { recursive: true });+ await userTurn.screenshot({+ path: path.join(captureDir, 'user-image.png'),+ animations: 'disabled',+ });+ }++ const imageBox = await image.locator('xpath=../..').boundingBox();+ const bubbleBox = await userTurn.getByTestId('message-body').boundingBox();+ if (imageBox == null || bubbleBox == null) {+ throw new Error('The user image and message bubble must have measurable bounds.');+ }+ const leftInset = imageBox.x - bubbleBox.x;+ const rightInset = bubbleBox.x + bubbleBox.width - (imageBox.x + imageBox.width);+ expect(leftInset - rightInset).toBeGreaterThan(40);+});