mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
🐛 fix: Keep Artifact Download Clear of Message Navigation (#17079)
* 🐛 fix: Keep Artifact Download Clear of Message Navigation * 🐛 fix: Clear Navigation for Every Artifact Download State * 🧪 test: Assert Artifact Download Clears Navigation Rail * 🐛 fix: Preserve Artifact Download Target Size * 🐛 fix: Tighten Artifact Navigation Clearance * 🐛 fix: Constrain Artifact Preview Rows to Message Width
This commit is contained in:
parent
ecd6943194
commit
60a8b3dec0
4 changed files with 176 additions and 5 deletions
|
|
@ -10,8 +10,8 @@ import {
|
|||
Workflow,
|
||||
} from 'lucide-react';
|
||||
import type { ArtifactGlyph, ArtifactRowKind } from '~/utils/artifacts';
|
||||
import { ARTIFACT_ROW_NAV_SPACING, ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from '../rows';
|
||||
import LangIcon, { hasLangIcon } from '~/components/Messages/Content/LangIcon';
|
||||
import { ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from '../rows';
|
||||
import { useLocalize } from '~/hooks';
|
||||
import { cn } from '~/utils';
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ const ArtifactRow = forwardRef<HTMLButtonElement, ArtifactRowProps>(function Art
|
|||
}
|
||||
|
||||
return (
|
||||
<div className={cn(TOOL_ROW_CLASSES, 'text-text-secondary text-sm')}>
|
||||
<div className={cn(TOOL_ROW_CLASSES, 'text-text-secondary text-sm', ARTIFACT_ROW_NAV_SPACING)}>
|
||||
<Button
|
||||
ref={ref}
|
||||
type="button"
|
||||
|
|
|
|||
|
|
@ -14,11 +14,11 @@ import {
|
|||
isTextAttachment,
|
||||
renderAttachmentKey,
|
||||
} from './attachmentTypes';
|
||||
import { ARTIFACT_ROW_NAV_SPACING, ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from '../rows';
|
||||
import { useLocalize, useAttachmentPreviewSync, useExpandCollapse } from '~/hooks';
|
||||
import FileContainer from '~/components/Chat/Input/Files/FileContainer';
|
||||
import { fileToArtifact, TOOL_ARTIFACT_TYPES } from '~/utils/artifacts';
|
||||
import Image from '~/components/Chat/Messages/Content/Image';
|
||||
import { ROW_GLYPH_SLOT, TOOL_ROW_CLASSES } from '../rows';
|
||||
import ToolMermaidArtifact from './ToolMermaidArtifact';
|
||||
import ToolArtifactCard from './ToolArtifactCard';
|
||||
import { useAttachmentLink } from './LogLink';
|
||||
|
|
@ -64,7 +64,9 @@ const PreviewPlaceholderRow = memo(
|
|||
? localize('com_ui_preview_preparing')
|
||||
: localize('com_ui_preview_failed');
|
||||
return (
|
||||
<div className={cn(TOOL_ROW_CLASSES, 'text-text-secondary text-sm')}>
|
||||
<div
|
||||
className={cn(TOOL_ROW_CLASSES, ARTIFACT_ROW_NAV_SPACING, 'text-text-secondary text-sm')}
|
||||
>
|
||||
<span className={ROW_GLYPH_SLOT} aria-hidden="true">
|
||||
{status === 'pending' ? (
|
||||
<Loader2 className="size-4 shrink-0 animate-spin" />
|
||||
|
|
@ -132,7 +134,7 @@ const FileAttachment = memo(({ attachment }: { attachment: Partial<TAttachment>
|
|||
return (
|
||||
<div
|
||||
className={cn(
|
||||
'subpixel-antialiased transition-all duration-300 ease-out',
|
||||
'w-full min-w-0 subpixel-antialiased transition-all duration-300 ease-out',
|
||||
isVisible ? 'translate-y-0 opacity-100' : 'translate-y-2 opacity-0',
|
||||
)}
|
||||
style={{
|
||||
|
|
|
|||
|
|
@ -7,6 +7,9 @@
|
|||
*/
|
||||
export const TOOL_ROW_CLASSES = 'relative my-1.5 flex h-5 shrink-0 items-center gap-2.5';
|
||||
|
||||
/** Leave an 8px gap beside MessageNav's hit area in full-width chat. */
|
||||
export const ARTIFACT_ROW_NAV_SPACING = 'pr-3 md:pr-17';
|
||||
|
||||
/** Behavior hook for header glyphs, independent of their layout. */
|
||||
export const FOLD_GLYPH_CLASS = 'fold-glyph';
|
||||
|
||||
|
|
|
|||
166
e2e/specs/mock/scenarios/artifact-download-message-nav.spec.ts
Normal file
166
e2e/specs/mock/scenarios/artifact-download-message-nav.spec.ts
Normal file
|
|
@ -0,0 +1,166 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
|
||||
const NO_PARENT = '00000000-0000-0000-0000-000000000000';
|
||||
|
||||
test.use({ viewport: { width: 1280, height: 800 } });
|
||||
|
||||
test('artifact downloads stay clickable beneath the message navigation rail across preview states and chat widths @scenario:artifact-download-clears-message-nav', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto('/');
|
||||
for (const status of ['ready', 'pending', 'failed'] as const) {
|
||||
for (const fullWidth of [false, true]) {
|
||||
await page.evaluate((value) => {
|
||||
localStorage.setItem('maximizeChatSpace', JSON.stringify(value));
|
||||
}, fullWidth);
|
||||
const conversationId = `artifact-nav-${Date.now()}-${status}-${fullWidth}`;
|
||||
const filename = `workbook-${'x'.repeat(100)}.xlsx`;
|
||||
const fileId = `${conversationId}-file`;
|
||||
const toolCallId = `${conversationId}-tool`;
|
||||
const now = new Date(0).toISOString();
|
||||
const base = { conversationId, createdAt: now, updatedAt: now };
|
||||
const messages = [
|
||||
{
|
||||
...base,
|
||||
messageId: `${conversationId}-user-1`,
|
||||
parentMessageId: NO_PARENT,
|
||||
isCreatedByUser: true,
|
||||
sender: 'User',
|
||||
text: 'Create a workbook.',
|
||||
},
|
||||
{
|
||||
...base,
|
||||
messageId: `${conversationId}-assistant-1`,
|
||||
parentMessageId: `${conversationId}-user-1`,
|
||||
isCreatedByUser: false,
|
||||
sender: 'Assistant',
|
||||
endpoint: 'Mock Provider A',
|
||||
model: 'mock-model-a',
|
||||
text: 'I will prepare it.',
|
||||
},
|
||||
{
|
||||
...base,
|
||||
messageId: `${conversationId}-user-2`,
|
||||
parentMessageId: `${conversationId}-assistant-1`,
|
||||
isCreatedByUser: true,
|
||||
sender: 'User',
|
||||
text: 'Finish the spreadsheet.',
|
||||
},
|
||||
{
|
||||
...base,
|
||||
messageId: `${conversationId}-assistant-2`,
|
||||
parentMessageId: `${conversationId}-user-2`,
|
||||
isCreatedByUser: false,
|
||||
sender: 'Assistant',
|
||||
endpoint: 'Mock Provider A',
|
||||
model: 'mock-model-a',
|
||||
text: '',
|
||||
content: [
|
||||
{
|
||||
type: 'tool_call',
|
||||
tool_call: {
|
||||
id: toolCallId,
|
||||
name: 'execute_code',
|
||||
args: '{}',
|
||||
output: 'done',
|
||||
progress: 1,
|
||||
},
|
||||
},
|
||||
{
|
||||
type: 'text',
|
||||
text: Array.from({ length: 80 }, (_, i) => `Analysis line ${i + 1}.`).join('\n\n'),
|
||||
},
|
||||
],
|
||||
attachments: [
|
||||
{
|
||||
file_id: fileId,
|
||||
filename,
|
||||
filepath: `/api/files/code/download/test-session/${fileId}`,
|
||||
type: 'execute_code',
|
||||
source: 'local',
|
||||
bytes: 2048,
|
||||
messageId: `${conversationId}-assistant-2`,
|
||||
conversationId,
|
||||
toolCallId,
|
||||
status,
|
||||
text: status === 'ready' ? '<table><tr><td>ready</td></tr></table>' : undefined,
|
||||
textFormat: status === 'ready' ? 'html' : undefined,
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
const conversation = {
|
||||
...base,
|
||||
title: 'Artifact navigation overlap',
|
||||
endpoint: 'Mock Provider A',
|
||||
endpointType: 'custom',
|
||||
model: 'mock-model-a',
|
||||
};
|
||||
await page.route(`**/api/convos/${conversationId}*`, (route) =>
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(conversation),
|
||||
}),
|
||||
);
|
||||
await page.route(`**/api/messages/${conversationId}*`, (route) =>
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify(messages),
|
||||
}),
|
||||
);
|
||||
let downloadRequests = 0;
|
||||
await page.route('**/api/files/code/download/test-session/**', (route) => {
|
||||
downloadRequests += 1;
|
||||
return route.fulfill({ status: 200, body: 'workbook bytes' });
|
||||
});
|
||||
|
||||
await page.goto(`/c/${conversationId}`);
|
||||
const download = page.getByRole('button', { name: `Download ${filename}` });
|
||||
await expect(download).toBeVisible();
|
||||
const nav = page.locator('nav[aria-keyshortcuts="Shift+Alt+M"]');
|
||||
await expect(nav).toBeVisible();
|
||||
if (fullWidth) {
|
||||
await expect(page.locator('.message-render').filter({ has: download })).toHaveClass(
|
||||
/max-w-full/,
|
||||
);
|
||||
}
|
||||
await download.scrollIntoViewIfNeeded();
|
||||
await download.evaluate((el) => {
|
||||
const rail = document.querySelector('nav[aria-keyshortcuts="Shift+Alt+M"]');
|
||||
if (!rail) {
|
||||
throw new Error('Message navigation rail is missing');
|
||||
}
|
||||
const railBox = rail.getBoundingClientRect();
|
||||
const targetY = railBox.top + railBox.height / 2;
|
||||
let scroller = el.parentElement;
|
||||
while (
|
||||
scroller &&
|
||||
!(
|
||||
scroller.scrollHeight > scroller.clientHeight + 10 &&
|
||||
/auto|scroll/.test(getComputedStyle(scroller).overflowY)
|
||||
)
|
||||
) {
|
||||
scroller = scroller.parentElement;
|
||||
}
|
||||
if (!scroller) {
|
||||
throw new Error('Message scroller is missing');
|
||||
}
|
||||
const box = el.getBoundingClientRect();
|
||||
scroller.scrollTop += box.top + box.height / 2 - targetY;
|
||||
});
|
||||
|
||||
const box = await download.boundingBox();
|
||||
const railBox = await nav.boundingBox();
|
||||
expect(box).not.toBeNull();
|
||||
expect(railBox).not.toBeNull();
|
||||
const center = { x: box!.x + box!.width / 2, y: box!.y + box!.height / 2 };
|
||||
expect(center.y).toBeGreaterThan(railBox!.y);
|
||||
expect(center.y).toBeLessThan(railBox!.y + railBox!.height);
|
||||
expect(box!.x + box!.width).toBeLessThanOrEqual(railBox!.x - 7);
|
||||
await page.mouse.click(center.x, center.y);
|
||||
await expect.poll(() => downloadRequests).toBe(1);
|
||||
}
|
||||
}
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue