mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-21 15:33:45 +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.
316 lines
12 KiB
TypeScript
316 lines
12 KiB
TypeScript
import { expect, test } from '@playwright/test';
|
|
import type { Page } from '@playwright/test';
|
|
import { clickHouseTheme } from '../../../../packages/client/src/theme/themes/clickhouse';
|
|
import { NEW_CHAT_PATH } from '../helpers';
|
|
|
|
/**
|
|
* The pressed and disabled state roles. A held control takes `surface-pressed` (or the inverted
|
|
* pressed fill), which defaults to the hover fill a pointer press has always shown. A disabled
|
|
* control dims to half opacity unless the theme's `disabledStyle` is `fill`, which paints it in
|
|
* `surface-disabled` and `text-disabled` at full opacity. The probes carry the class lists the
|
|
* shared `IconButton` and `Field` primitives compose, so only those rules style them.
|
|
*/
|
|
|
|
type Mode = 'light' | 'dark';
|
|
|
|
const PRESS_CLASSES = 'bg-surface-secondary hover:bg-surface-hover hover:active:bg-surface-pressed';
|
|
const DISABLED_CLASSES =
|
|
'bg-transparent text-text-primary disabled:opacity-50 theme-disabled:bg-surface-disabled theme-disabled:text-text-disabled theme-disabled:opacity-100';
|
|
|
|
/** Names every state role apart from the hover and ink it would otherwise follow. */
|
|
const STATE_ROLE_THEME = {
|
|
version: 1,
|
|
name: 'e2e-state-roles',
|
|
modes: {
|
|
light: {
|
|
colors: {
|
|
'rgb-surface-hover': '200 200 200',
|
|
'rgb-surface-pressed': '150 60 20',
|
|
'rgb-surface-disabled': '20 150 60',
|
|
'rgb-text-disabled': '60 20 150',
|
|
},
|
|
appearance: { disabledStyle: 'fill' },
|
|
},
|
|
dark: {
|
|
colors: {
|
|
'rgb-surface-hover': '60 60 60',
|
|
'rgb-surface-pressed': '240 160 120',
|
|
'rgb-surface-disabled': '120 240 160',
|
|
'rgb-text-disabled': '160 120 240',
|
|
},
|
|
appearance: { disabledStyle: 'fill' },
|
|
},
|
|
},
|
|
} as const;
|
|
|
|
async function openChat(page: Page, mode: Mode, definition?: { name: string }) {
|
|
await page.addInitScript(
|
|
([appearance, stored]) => {
|
|
localStorage.setItem('color-theme', appearance as string);
|
|
localStorage.removeItem('theme-colors');
|
|
localStorage.removeItem('theme-name');
|
|
if (stored) {
|
|
localStorage.setItem('theme-definition', JSON.stringify(stored));
|
|
localStorage.setItem('theme-source', 'definition');
|
|
} else {
|
|
localStorage.removeItem('theme-definition');
|
|
localStorage.removeItem('theme-source');
|
|
}
|
|
},
|
|
[mode, definition ?? null] as [string, unknown],
|
|
);
|
|
await page.goto(NEW_CHAT_PATH, { timeout: 15000 });
|
|
await expect(page.getByRole('textbox', { name: 'Message input' })).toBeVisible({
|
|
timeout: 30000,
|
|
});
|
|
const root = page.locator('html');
|
|
if (definition) {
|
|
await expect(root).toHaveAttribute('data-theme', definition.name);
|
|
} else {
|
|
await expect(root).not.toHaveAttribute('data-theme');
|
|
}
|
|
await expect(root).toHaveClass(mode === 'dark' ? /\bdark\b/ : /\blight\b/);
|
|
}
|
|
|
|
async function addProbe(page: Page, id: string, className: string, disabled = false) {
|
|
await page.evaluate(
|
|
([probeId, classes, isDisabled]) => {
|
|
const probe = document.createElement('button');
|
|
probe.id = probeId as string;
|
|
probe.className = classes as string;
|
|
probe.disabled = isDisabled as boolean;
|
|
probe.textContent = 'State probe';
|
|
probe.style.position = 'fixed';
|
|
probe.style.top = '8px';
|
|
probe.style.left = '8px';
|
|
probe.style.zIndex = '2147483647';
|
|
document.body.append(probe);
|
|
},
|
|
[id, className, disabled] as [string, string, boolean],
|
|
);
|
|
return page.locator(`#${id}`);
|
|
}
|
|
|
|
/**
|
|
* Holds the pointer down on a hovered probe and reads its fill. Tailwind gates `hover:` behind
|
|
* `(hover: hover)`, so on a touch device neither the hover nor the pressed fill applies and the
|
|
* probe keeps its resting fill, as it always has; `null` marks that case.
|
|
*/
|
|
async function pressedFill(page: Page): Promise<string | null> {
|
|
if (!(await page.evaluate(() => matchMedia('(hover: hover)').matches))) {
|
|
return null;
|
|
}
|
|
const probe = await addProbe(page, 'state-press-probe', PRESS_CLASSES);
|
|
const box = await probe.boundingBox();
|
|
if (!box) {
|
|
throw new Error('press probe has no box');
|
|
}
|
|
await page.mouse.move(box.x + box.width / 2, box.y + box.height / 2);
|
|
await page.mouse.down();
|
|
const fill = await probe.evaluate((node) => getComputedStyle(node).backgroundColor);
|
|
await page.mouse.up();
|
|
return fill;
|
|
}
|
|
|
|
/** The ink an empty disabled field shows is its placeholder, which `Field` colors on its own. */
|
|
const PLACEHOLDER_CLASSES =
|
|
'placeholder:text-text-secondary disabled:opacity-50 theme-disabled:placeholder:text-text-disabled';
|
|
|
|
async function disabledLook(page: Page) {
|
|
const probe = await addProbe(page, 'state-disabled-probe', DISABLED_CLASSES, true);
|
|
const look = await probe.evaluate((node) => {
|
|
const style = getComputedStyle(node);
|
|
return { fill: style.backgroundColor, ink: style.color, opacity: style.opacity };
|
|
});
|
|
const placeholder = await page.evaluate((classes) => {
|
|
const field = document.createElement('input');
|
|
field.className = classes;
|
|
field.placeholder = 'Disabled field';
|
|
field.disabled = true;
|
|
document.body.append(field);
|
|
const color = getComputedStyle(field, '::placeholder').color;
|
|
field.remove();
|
|
return color;
|
|
}, PLACEHOLDER_CLASSES);
|
|
/** Radix marks a disabled part that is not a form control, a slider thumb, with `data-disabled`. */
|
|
const part = await page.evaluate(() => {
|
|
const thumb = document.createElement('span');
|
|
thumb.className = 'bg-surface-primary theme-disabled:bg-surface-disabled';
|
|
thumb.setAttribute('data-disabled', '');
|
|
document.body.append(thumb);
|
|
const fill = getComputedStyle(thumb).backgroundColor;
|
|
thumb.remove();
|
|
return fill;
|
|
});
|
|
/** `InputNumber` styles a wrapper whose disabled input sits inside it, and adds the classes
|
|
* for its parts itself while that input is disabled. */
|
|
const wrapper = await page.evaluate(() => {
|
|
const box = document.createElement('div');
|
|
box.className =
|
|
'bg-transparent text-text-primary theme-disabled-within:bg-surface-disabled theme-disabled-within:text-text-disabled theme-disabled-fill:[&_*]:border-border-disabled';
|
|
const field = document.createElement('input');
|
|
field.disabled = true;
|
|
const slot = document.createElement('div');
|
|
slot.className = 'border border-border-control';
|
|
box.append(field, slot);
|
|
document.body.append(box);
|
|
const style = getComputedStyle(box);
|
|
const result = `${style.backgroundColor} ${getComputedStyle(field).color} ${getComputedStyle(slot).borderTopColor}`;
|
|
box.remove();
|
|
return result;
|
|
});
|
|
/** A menu item keeps its surface and grays its text; a label follows its control through `peer`. */
|
|
const items = await page.evaluate(() => {
|
|
const item = document.createElement('div');
|
|
item.className =
|
|
'text-text-primary theme-disabled:text-text-disabled theme-disabled:[&_*]:text-text-disabled';
|
|
item.setAttribute('data-disabled', '');
|
|
const icon = document.createElementNS('http://www.w3.org/2000/svg', 'svg');
|
|
icon.setAttribute('class', 'text-status-warning');
|
|
item.append(icon);
|
|
const field = document.createElement('input');
|
|
field.className = 'peer';
|
|
field.disabled = true;
|
|
const label = document.createElement('label');
|
|
label.className = 'text-text-secondary peer-theme-disabled:text-text-disabled';
|
|
document.body.append(item, field, label);
|
|
const result = `${getComputedStyle(icon).color} ${getComputedStyle(label).color}`;
|
|
item.remove();
|
|
field.remove();
|
|
label.remove();
|
|
return result;
|
|
});
|
|
return { ...look, placeholder, part, wrapper, items };
|
|
}
|
|
|
|
/** Each tag is written out whole: the runner finds a scenario by its literal tag. */
|
|
const CASES: Array<{
|
|
title: string;
|
|
mode: Mode;
|
|
definition?: { name: string };
|
|
pressed: string;
|
|
disabled: {
|
|
fill: string;
|
|
ink: string;
|
|
opacity: string;
|
|
placeholder: string;
|
|
part: string;
|
|
wrapper: string;
|
|
items: string;
|
|
};
|
|
}> = [
|
|
{
|
|
title:
|
|
'the default light theme presses in its hover fill and dims disabled controls @scenario:state-roles-default-light-unchanged',
|
|
mode: 'light',
|
|
pressed: 'rgb(227, 227, 227)',
|
|
disabled: {
|
|
fill: 'rgba(0, 0, 0, 0)',
|
|
ink: 'rgb(33, 33, 33)',
|
|
opacity: '0.5',
|
|
placeholder: 'rgb(66, 66, 66)',
|
|
part: 'rgb(255, 255, 255)',
|
|
wrapper: 'rgba(0, 0, 0, 0) rgb(33, 33, 33) rgb(227, 227, 227)',
|
|
items: 'rgb(180, 83, 9) rgb(66, 66, 66)',
|
|
},
|
|
},
|
|
{
|
|
title:
|
|
'the default dark theme presses in its hover fill and dims disabled controls @scenario:state-roles-default-dark-unchanged',
|
|
mode: 'dark',
|
|
pressed: 'rgb(57, 57, 57)',
|
|
disabled: {
|
|
fill: 'rgba(0, 0, 0, 0)',
|
|
ink: 'rgb(236, 236, 236)',
|
|
opacity: '0.5',
|
|
placeholder: 'rgb(205, 205, 205)',
|
|
part: 'rgb(13, 13, 13)',
|
|
wrapper: 'rgba(0, 0, 0, 0) rgb(236, 236, 236) rgb(33, 33, 33)',
|
|
items: 'rgb(252, 211, 77) rgb(205, 205, 205)',
|
|
},
|
|
},
|
|
{
|
|
title:
|
|
'the ClickHouse light theme presses and disables in Click UI fills @scenario:state-roles-clickhouse-light',
|
|
mode: 'light',
|
|
definition: clickHouseTheme,
|
|
pressed: 'rgb(230, 231, 233)',
|
|
disabled: {
|
|
fill: 'rgb(223, 223, 223)',
|
|
ink: 'rgb(160, 160, 160)',
|
|
opacity: '1',
|
|
placeholder: 'rgb(160, 160, 160)',
|
|
part: 'rgb(223, 223, 223)',
|
|
wrapper: 'rgb(223, 223, 223) rgb(160, 160, 160) rgb(223, 223, 223)',
|
|
items: 'rgb(160, 160, 160) rgb(160, 160, 160)',
|
|
},
|
|
},
|
|
{
|
|
title:
|
|
'the ClickHouse dark theme presses and disables in Click UI fills @scenario:state-roles-clickhouse-dark',
|
|
mode: 'dark',
|
|
definition: clickHouseTheme,
|
|
pressed: 'rgb(50, 50, 50)',
|
|
disabled: {
|
|
fill: 'rgb(65, 65, 65)',
|
|
ink: 'rgb(128, 128, 128)',
|
|
opacity: '1',
|
|
placeholder: 'rgb(128, 128, 128)',
|
|
part: 'rgb(65, 65, 65)',
|
|
wrapper: 'rgb(65, 65, 65) rgb(128, 128, 128) rgb(65, 65, 65)',
|
|
items: 'rgb(128, 128, 128) rgb(128, 128, 128)',
|
|
},
|
|
},
|
|
];
|
|
|
|
test.describe('pressed and disabled state roles', () => {
|
|
for (const { title, mode, definition, pressed, disabled } of CASES) {
|
|
test(title, async ({ page }) => {
|
|
await openChat(page, mode, definition);
|
|
|
|
const fill = await pressedFill(page);
|
|
if (fill !== null) {
|
|
expect(fill).toBe(pressed);
|
|
}
|
|
expect(await disabledLook(page)).toEqual(disabled);
|
|
});
|
|
}
|
|
|
|
test('a theme that names the state roles presses and disables in them, in both modes @scenario:state-roles-follow-reference-theme', async ({
|
|
page,
|
|
}) => {
|
|
const expected: Record<Mode, { pressed: string; fill: string; ink: string; edge: string }> = {
|
|
light: {
|
|
pressed: 'rgb(150, 60, 20)',
|
|
fill: 'rgb(20, 150, 60)',
|
|
ink: 'rgb(60, 20, 150)',
|
|
edge: 'rgb(227, 227, 227)',
|
|
},
|
|
dark: {
|
|
pressed: 'rgb(240, 160, 120)',
|
|
fill: 'rgb(120, 240, 160)',
|
|
ink: 'rgb(160, 120, 240)',
|
|
edge: 'rgb(57, 57, 57)',
|
|
},
|
|
};
|
|
/** One page per mode: a page's init scripts accumulate, and their order is not guaranteed. */
|
|
for (const mode of ['light', 'dark'] as const) {
|
|
const modePage = mode === 'light' ? page : await page.context().newPage();
|
|
await openChat(modePage, mode, STATE_ROLE_THEME);
|
|
|
|
const fill = await pressedFill(modePage);
|
|
if (fill !== null) {
|
|
expect(fill).toBe(expected[mode].pressed);
|
|
}
|
|
expect(await disabledLook(modePage)).toEqual({
|
|
fill: expected[mode].fill,
|
|
ink: expected[mode].ink,
|
|
opacity: '1',
|
|
placeholder: expected[mode].ink,
|
|
part: expected[mode].fill,
|
|
wrapper: `${expected[mode].fill} ${expected[mode].ink} ${expected[mode].edge}`,
|
|
items: `${expected[mode].ink} ${expected[mode].ink}`,
|
|
});
|
|
}
|
|
});
|
|
});
|