mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-18 14:08:21 +00:00
* 🎞️ perf: Run the In-Flight Label Sweep on the Compositor The sweep on a running tool call, streaming reasoning and the elapsed timer animated `background-position` under `background-clip: text`, which no browser can hand to the compositor. Every frame of it ran style, paint and commit on the main thread, and each paint walked the transcript around the label, so the cost of a frame grew with the conversation and the sweep stuttered whenever the main thread was busy. `Shimmer` in `@librechat/client` draws the same sweep from two transforms that cancel: a masked band slides across the label while a second copy of the text inside it slides back, so the glyphs hold still and only the gap in the mask moves. The copy is generated content, so the label is still one text node. Every in-flight label renders through it. `e2e/benchmarks-fade` measures a frame and each kind of stream event inside an exported conversation, from a Chromium trace of the built client. * 🧪 test: Let the Frame Benchmark Open a Chat in a Chosen Theme * 🧵 perf: Keep the Composer, Nav Rail and Row Toolbars Out of Every Stream Event A streamed delta rewrites one row, but each one also re-rendered the composer form (and re-measured its textarea), the message nav rail (re-translating a label per message), the sidebar's chat provider and the pending-steers row, because each subscribed to the whole streaming message or the whole messages array to read something a delta never changes. - The chat contract and steering read a projection of the branch tail (where it sits, whether the run is paused) and fetch the message itself when a turn is built, through `useBranchTailGetter`. `ChatTurnsParams` carries `getLatestMessage` in place of `latestMessage`. - The compact action and pending steers select what they use of the tail. - The URL-prompt hook observes the history only while a submission waits on it. - The nav rail's ribs are memoized apart from the rail. - A row's toolbar keeps one element per glyph and stable handlers, so a send and its completion no longer re-render every button of every row. `e2e/benchmarks-fade` gains a render-reason probe (`FADE_PERF_WHY`), a whole-run profile, and windows for the send and its confirming frame. * 🫥 perf: Conceal Rerun During a Run Instead of Unmounting It on Every Row A run starting or ending withholds, then restores, the rerun control on every row of the thread at once. Unmounting and remounting a button on each row made the browser re-style the whole transcript both times: the stylesheet holds `:has(:disabled)` rules and a message row is a `:has()` anchor, so a button entering, leaving or flipping `disabled` inside a row invalidates that row's entire subtree. In a 250-message thread that was 80 to 100 ms inside the send keypress and again inside the final frame. The control now stays mounted for as long as the row has a rerun to offer and is concealed by visibility while a run is in flight: no focus, no pointer, no place in the accessibility tree, and no layout where the toolbar starts at the row's edge. Below `lg`, where the toolbar is centered, it leaves the flow as before. It is deliberately not also `disabled`. The reply being written still mounts no controls at all. * 🎯 perf: Write :has() Rules So a Change in a Row Does Not Re-style the Row Two selector shapes in the stylesheet left the browser unable to tell which elements a `:has()` rule could reach, so it re-styled the whole subtree of every `:has()` anchor above any change: - Tailwind's `group-has-[…]`, which compiles to `.x:is(:where(.group):has(…) *)`. Message rows and their toolbars are `group`s, so a button mounting or unmounting in a row re-styled the row. - `theme-disabled-within:[&_*]:…`, which compiles to `…:has(:disabled) *`. With it in the sheet, a `disabled` flip did the same. Either one alone was enough: flipping `disabled` on one button per row of a 250-message thread took 100 to 110 ms, and mounting one took 88 ms. A run starting or ending did one of those on every row. The row-hover reveal, the header label crossfade and the toolbar's hover-active hold now use `grouped-*` custom variants that emit `:where(.group):has(…) .x`: the same elements at the same specificity, with a subject the browser can read. A wrapper's parts take the disabled fill from classes the component adds while it is disabled, through `theme-disabled-fill`, instead of from `:has(:disabled) *`. The same two changes now cost 25 to 42 ms and 27 ms. `has-selectors.spec.ts` reads the stylesheet the app ships and fails on either shape; `restyle.perf.spec.ts` measures the cost. * 📱 fix: Keep a Concealed Rerun Hidden on Narrow Screens The narrow-screen stylesheet forces every toolbar button visible from outside any cascade layer, so it outranked the utilities that conceal a rerun while a run is in flight: below 1024px the button stayed on screen and in the tab order, inert. A concealed button now carries `data-concealed`, and that rule leaves it alone. Covered at a narrow and a wide viewport by what the reader gets: the settled reply's rerun is hidden and cannot take focus during a run, and is back after. * 🧮 perf: Skip the Pause Scan in Pending Steers When None Are Pending The pending-steers row follows the conversation's messages, so it renders for every streamed delta, and it resolved the run's pause state before checking whether it had anything to show. That check walks every part of every message. It now runs only with a steer to display.
212 lines
7.9 KiB
TypeScript
212 lines
7.9 KiB
TypeScript
import { randomUUID } from 'node:crypto';
|
|
import { expect, test } from '@playwright/test';
|
|
import type { Page } from '@playwright/test';
|
|
import { getE2EUser } from '../../../setup/user';
|
|
import {
|
|
replyText,
|
|
replyPrompt,
|
|
NEW_CHAT_PATH,
|
|
messagesView,
|
|
MOCK_ENDPOINTS,
|
|
isAgentsStream,
|
|
sendMessage,
|
|
selectMockEndpoint,
|
|
sendMessageAndWaitForCompletion,
|
|
} from '../helpers';
|
|
import {
|
|
seedMessages,
|
|
seedConversations,
|
|
deleteConversations,
|
|
deleteMessagesByConversation,
|
|
} from '../db';
|
|
|
|
/** The toolbar `@librechat/chat` renders under each turn: rerun, continue, edit, copy and
|
|
* read-aloud, with the thread and the read-aloud control supplied by the app's messages host. */
|
|
|
|
const ROOT_PARENT = '00000000-0000-0000-0000-000000000000';
|
|
const userEmail = getE2EUser().email;
|
|
const createdConversationIds: string[] = [];
|
|
|
|
test.describe.configure({ timeout: 120_000 });
|
|
|
|
test.afterAll(async () => {
|
|
await deleteMessagesByConversation(createdConversationIds);
|
|
await deleteConversations(createdConversationIds);
|
|
});
|
|
|
|
const messageRender = (page: Page, text: string) =>
|
|
page.locator('.message-render').filter({ hasText: text }).last();
|
|
|
|
async function replyInNewChat(page: Page, prefix: string) {
|
|
const label = `${prefix}-${randomUUID().slice(0, 8)}`;
|
|
await page.goto(NEW_CHAT_PATH, { timeout: 10000 });
|
|
await selectMockEndpoint(page, MOCK_ENDPOINTS[0]);
|
|
const response = await sendMessageAndWaitForCompletion(page, replyPrompt(label));
|
|
expect(response.ok()).toBeTruthy();
|
|
const reply = replyText(label);
|
|
await expect(messagesView(page).getByText(reply)).toBeVisible({ timeout: 30000 });
|
|
const conversationId = new URL(page.url()).pathname.split('/c/')[1];
|
|
if (conversationId) {
|
|
createdConversationIds.push(conversationId);
|
|
}
|
|
return { label, reply };
|
|
}
|
|
|
|
/**
|
|
* A run in flight withholds rerun on every settled reply without removing the button, so the
|
|
* check is what the reader gets, not which classes the button carries: nothing to see, nothing
|
|
* to focus, and the same button back when the run ends. Below `lg` the app's own stylesheet
|
|
* forces toolbar buttons visible, which a concealed one has to be exempt from.
|
|
*/
|
|
async function expectRerunWithheldDuringRun(page: Page, width: number) {
|
|
const { reply, label } = await replyInNewChat(page, 'hover-conceal');
|
|
await page.setViewportSize({ width, height: 900 });
|
|
const row = messageRender(page, reply);
|
|
const rerun = row.locator('button[aria-label="Regenerate"]');
|
|
await row.hover();
|
|
await expect(rerun).toBeVisible();
|
|
|
|
const run = await sendMessage(page, `E2E_SLOW_REPLY:${label}`);
|
|
expect(run.ok()).toBeTruthy();
|
|
const stop = page.getByTestId('stop-generation-button');
|
|
await expect(stop).toBeVisible({ timeout: 15_000 });
|
|
|
|
await row.hover();
|
|
await expect(rerun).toHaveCount(1);
|
|
await expect(rerun).toBeHidden();
|
|
const tookFocus = await rerun.evaluate((button: HTMLElement) => {
|
|
button.focus();
|
|
return document.activeElement === button;
|
|
});
|
|
expect(tookFocus).toBe(false);
|
|
|
|
await expect(stop).toBeHidden({ timeout: 60_000 });
|
|
await row.hover();
|
|
await expect(rerun).toBeVisible();
|
|
}
|
|
|
|
test.describe('message hover toolbar', () => {
|
|
test('a settled reply withholds rerun on a wide screen while a run is in flight @scenario:hover-rerun-withheld-during-run-wide', async ({
|
|
page,
|
|
}) => {
|
|
await expectRerunWithheldDuringRun(page, 1280);
|
|
});
|
|
|
|
test('a settled reply withholds rerun on a narrow screen while a run is in flight @scenario:hover-rerun-withheld-during-run-narrow', async ({
|
|
page,
|
|
}) => {
|
|
await expectRerunWithheldDuringRun(page, 800);
|
|
});
|
|
|
|
test('regenerating a reply replays its turn @scenario:hover-regenerate-replays-turn', async ({
|
|
page,
|
|
}) => {
|
|
const { reply } = await replyInNewChat(page, 'hover-regen');
|
|
|
|
const row = messageRender(page, reply);
|
|
await row.hover();
|
|
const [response] = await Promise.all([
|
|
page.waitForResponse(isAgentsStream, { timeout: 30000 }),
|
|
page.getByTestId('regenerate-generation-button').click(),
|
|
]);
|
|
expect(response.ok()).toBeTruthy();
|
|
await expect(messagesView(page).getByText('2 / 2')).toBeVisible({ timeout: 30000 });
|
|
await expect(messagesView(page).getByText(reply)).toBeVisible();
|
|
});
|
|
|
|
test('a cut-off reply offers continue and a finished one does not @scenario:hover-continue-on-cut-off-reply', async ({
|
|
page,
|
|
}) => {
|
|
const { reply } = await replyInNewChat(page, 'hover-finished');
|
|
await messageRender(page, reply).hover();
|
|
await expect(page.getByTestId('regenerate-generation-button')).toBeVisible();
|
|
await expect(page.getByTestId('continue-generation-button')).toHaveCount(0);
|
|
|
|
const conversationId = randomUUID();
|
|
const userMessageId = randomUUID();
|
|
const responseId = randomUUID();
|
|
await seedConversations(userEmail, [
|
|
{ conversationId, title: `Cut off ${conversationId.slice(0, 8)}`, updatedAt: new Date() },
|
|
]);
|
|
createdConversationIds.push(conversationId);
|
|
await seedMessages(userEmail, conversationId, [
|
|
{
|
|
messageId: userMessageId,
|
|
parentMessageId: ROOT_PARENT,
|
|
text: 'Write a long answer',
|
|
isCreatedByUser: true,
|
|
sender: 'User',
|
|
},
|
|
{
|
|
messageId: responseId,
|
|
parentMessageId: userMessageId,
|
|
text: 'The answer stopped at the token lim',
|
|
isCreatedByUser: false,
|
|
sender: 'OpenAI',
|
|
finish_reason: 'length',
|
|
},
|
|
]);
|
|
|
|
await page.goto(`/c/${conversationId}`);
|
|
const row = page.locator(`[id="${responseId}"]`);
|
|
await expect(row).toBeVisible();
|
|
await row.hover();
|
|
await expect(page.getByTestId('continue-generation-button')).toBeVisible();
|
|
await expect(page.getByTestId('continue-generation-button')).toHaveAccessibleName('Continue');
|
|
});
|
|
|
|
test('editing a sent message opens its editor and cancel closes it @scenario:hover-edit-opens-editor', async ({
|
|
page,
|
|
}) => {
|
|
const { label } = await replyInNewChat(page, 'hover-edit');
|
|
const prompt = replyPrompt(label);
|
|
|
|
const row = messageRender(page, prompt);
|
|
await row.hover();
|
|
await row.getByRole('button', { name: 'Edit', exact: true }).click();
|
|
const editor = messagesView(page).getByTestId('message-text-editor');
|
|
await expect(editor).toHaveValue(prompt);
|
|
await expect(editor).toBeFocused();
|
|
|
|
await messagesView(page).getByRole('button', { name: 'Cancel', exact: true }).click();
|
|
await expect(editor).toHaveCount(0);
|
|
await expect(messagesView(page).getByText(prompt)).toBeVisible();
|
|
});
|
|
|
|
test('copying a reply puts its text on the clipboard @scenario:hover-copy-writes-clipboard', async ({
|
|
page,
|
|
context,
|
|
}) => {
|
|
await context.grantPermissions(['clipboard-read', 'clipboard-write']);
|
|
const { reply } = await replyInNewChat(page, 'hover-copy');
|
|
|
|
const row = messageRender(page, reply);
|
|
await row.hover();
|
|
await row.getByTestId('copy-response-button').click();
|
|
await expect(row.getByRole('button', { name: 'Copied to clipboard' })).toBeVisible();
|
|
const copied = await page.evaluate(() => navigator.clipboard.readText());
|
|
expect(copied).toContain(reply);
|
|
});
|
|
|
|
test('read aloud shows on a reply while text to speech is on @scenario:hover-read-aloud-with-tts-on', async ({
|
|
page,
|
|
}) => {
|
|
const { reply } = await replyInNewChat(page, 'hover-tts-on');
|
|
|
|
const row = messageRender(page, reply);
|
|
await row.hover();
|
|
await expect(row.getByRole('button', { name: 'Read aloud' })).toBeVisible();
|
|
});
|
|
|
|
test('read aloud is absent while text to speech is off @scenario:hover-read-aloud-absent-with-tts-off', async ({
|
|
page,
|
|
}) => {
|
|
await page.addInitScript(() => localStorage.setItem('textToSpeech', JSON.stringify(false)));
|
|
const { reply } = await replyInNewChat(page, 'hover-tts-off');
|
|
|
|
const row = messageRender(page, reply);
|
|
await row.hover();
|
|
await expect(row.getByTestId('copy-response-button')).toBeVisible();
|
|
await expect(row.getByRole('button', { name: 'Read aloud' })).toHaveCount(0);
|
|
});
|
|
});
|