From eb5d74dbd5f626b3f263f4e19b946db28e92ef92 Mon Sep 17 00:00:00 2001 From: Marco Beretta <81851188+berry-13@users.noreply.github.com> Date: Wed, 30 Sep 2026 10:59:06 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=91=E2=80=8D=F0=9F=8E=A8=20feat:=20Giv?= =?UTF-8?q?e=20the=20Default=20Avatar=20and=20Avatar=20Placeholder=20Theme?= =?UTF-8?q?=20Roles=20(#16545)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * feat: Give the Default Avatar and Avatar Placeholder Theme Roles The default user avatar filled with a literal rgb(121, 137, 255) in Avatar, MessageIcon and the endpoint Icon, and agent and assistant avatars sat on surface-secondary in light and a dark: surface-tertiary override, so no theme could repaint either. avatar-fill and avatar-text paint the default avatar and its glyph, and avatar-placeholder paints the backdrop behind an agent or assistant image. Every bundled theme reproduces today's pixels. A theme that sets only its surfaces keeps the placeholder on the surface its mode used before the role existed, both when resolved and through the legacy applyTheme path. ClickHouse takes Click UI's avatar fill and text and its muted background. * test: Pin the Default Avatar Fill With and Without the ClickHouse Theme The sidebar account avatar falls back to the default avatar when its image fails; with no theme it keeps rgb(121, 137, 255) in both modes and the placeholder keeps the surface its mode used, and under ClickHouse both take the Click UI values. * fix: Ink Every Default Avatar Glyph With the Avatar Text Role The sidebar Avatar, the only default avatar the chat renders, still inked its glyph in text-primary, so a theme's avatar-text never reached it and ClickHouse drew a dark glyph where Click UI draws white. Avatar now reads avatar-text, which defaults to each bundled theme's primary text and follows rgb-text-primary in a theme that does not set it, through resolveTheme and the legacy applyTheme path, so every rendered default avatar keeps its pixels. * fix: Read the Active Mode Off the Root When applyTheme Is Not Told It applyTheme is exported, and a caller that applies a legacy palette in dark mode without the new mode argument derived the avatar placeholder from the light surface. It now falls back to the root's dark class. * fix: Keep CSS-Themed Avatars on Their Legacy Source Variables The avatar text and placeholder defaults were literal triplets, so a consumer theming through --text-primary and the surface variables left avatars on the stock colors. They now alias text-primary, the secondary surface and, in dark, the tertiary surface, resolving to the same pixels by default. applyTheme's mode fallback also reads a dark ancestor, not only the root itself. * fix: Let the Stylesheet Alias Carry the Document Root Avatar Backdrop applyTheme wrote the legacy placeholder inline for the mode active when it ran, which then overrode the per-mode stylesheet alias after a dark toggle without a reapply. On the document root the alias already follows the theme's surfaces and the mode, so the placeholder is now derived only for a scoped root, which that alias cannot see. * fix: Keep a Scoped Legacy Avatar Backdrop Following the Mode applyTheme wrote a scoped root's avatar placeholder inline for the mode active when it ran, so after a later dark toggle the backdrop stayed on the light surface, where canary's dark:bg-surface-tertiary switched. applyTheme now marks a scoped root with data-theme-scope and the stylesheet points its backdrop at that root's own secondary surface, or its tertiary one under a .dark ancestor, as the document root's alias does. The mode argument is no longer needed and is removed. (cherry picked from commit 3ac6a0af3764855657905bbfd7bde11b9e420db3) Original-PR: https://github.com/LibreChat-AI/LibreChat/pull/16545 --- client/src/components/Endpoints/ConvoIcon.tsx | 3 +- client/src/components/Endpoints/Icon.tsx | 3 +- client/src/components/Share/MessageIcon.tsx | 3 +- .../components/SidePanel/Agents/Images.tsx | 2 +- .../components/SidePanel/Builder/Images.tsx | 2 +- .../mock/scenarios/clickhouse-theme.spec.ts | 128 ++++++++++++++++++ eslint-suppressions.json | 6 +- packages/client/src/components/Avatar.tsx | 3 +- packages/client/src/theme/README.md | 7 + packages/client/src/theme/defaults.css | 17 +++ packages/client/src/theme/defaults.spec.ts | 2 +- packages/client/src/theme/registry.spec.ts | 58 ++++++++ packages/client/src/theme/registry.ts | 20 +++ .../client/src/theme/semanticTokens.spec.ts | 25 ++++ .../client/src/theme/themes/clickhouse.ts | 6 + packages/client/src/theme/themes/clickui.json | 4 + .../client/src/theme/themes/clickui.spec.ts | 6 + packages/client/src/theme/themes/dark.ts | 3 + packages/client/src/theme/themes/default.ts | 3 + .../client/src/theme/themes/highContrast.ts | 6 + packages/client/src/theme/tokens.css | 3 + packages/client/src/theme/types/index.ts | 13 ++ .../client/src/theme/utils/applyTheme.spec.ts | 50 +++++++ packages/client/src/theme/utils/applyTheme.ts | 15 ++ packages/data-provider/src/theme.ts | 3 + 25 files changed, 377 insertions(+), 14 deletions(-) diff --git a/client/src/components/Endpoints/ConvoIcon.tsx b/client/src/components/Endpoints/ConvoIcon.tsx index ee39975b24..28549216c2 100644 --- a/client/src/components/Endpoints/ConvoIcon.tsx +++ b/client/src/components/Endpoints/ConvoIcon.tsx @@ -11,8 +11,7 @@ import { isImageURL } from '~/utils/icons'; /** Callers frame the mark at two thirds of the round container around it. */ const artScale = 2 / 3; -const entityAvatarClassName = - 'bg-surface-secondary h-full w-full rounded-full object-cover dark:bg-surface-tertiary'; +const entityAvatarClassName = 'bg-avatar-placeholder h-full w-full rounded-full object-cover'; function AgentAvatar({ avatar, diff --git a/client/src/components/Endpoints/Icon.tsx b/client/src/components/Endpoints/Icon.tsx index 7de5e39185..c674520e1d 100644 --- a/client/src/components/Endpoints/Icon.tsx +++ b/client/src/components/Endpoints/Icon.tsx @@ -84,12 +84,11 @@ const UserAvatar = memo( ) : (
diff --git a/client/src/components/Share/MessageIcon.tsx b/client/src/components/Share/MessageIcon.tsx index 309d236796..fc57309d83 100644 --- a/client/src/components/Share/MessageIcon.tsx +++ b/client/src/components/Share/MessageIcon.tsx @@ -68,12 +68,11 @@ export default function MessageIcon( return (
diff --git a/client/src/components/SidePanel/Agents/Images.tsx b/client/src/components/SidePanel/Agents/Images.tsx index 73cc936a1f..2667e335f7 100644 --- a/client/src/components/SidePanel/Agents/Images.tsx +++ b/client/src/components/SidePanel/Agents/Images.tsx @@ -40,7 +40,7 @@ export const AgentAvatarRender = ({ url }: { url?: string }) => {
Agent avatar GPT .getByText(title, { exact: true }) .evaluate((node) => getComputedStyle(node).color); +const MISSING_AVATAR = 'https://avatar.e2e.invalid/missing.png'; + +/** The e2e user has an avatar seed, so the default avatar only draws once its image fails: + * the user payload points at an address the page refuses to load. */ +async function failUserAvatar(page: Page) { + await page.route(`${MISSING_AVATAR}*`, (route) => route.abort()); + await page.route('**/api/user', async (route) => { + const response = await route.fetch(); + const user = await response.json(); + await route.fulfill({ response, json: { ...user, avatar: MISSING_AVATAR } }); + }); +} + +/** The default avatar on the sidebar account button, the one a signed-in user always sees. */ +const navAvatarPaint = async (page: Page) => { + const avatar = page.getByTestId('nav-user').locator('div[aria-hidden="true"]').first(); + await expect(avatar).toBeVisible({ timeout: 20000 }); + return avatar.evaluate((node) => { + const style = getComputedStyle(node); + return { fill: style.backgroundColor, ink: style.color }; + }); +}; + test.describe('clickhouse reference theme', () => { test('the ClickHouse definition repaints the chat and the settings dialog in both modes @scenario:clickhouse-definition-repaints-chat-sidebar-and-dialog', async ({ page, @@ -234,4 +257,109 @@ test.describe('clickhouse reference theme', () => { await deleteConversations([conversationId]); } }); + + test('the default avatar keeps its fill and the placeholder its surface without a theme @scenario:default-avatar-keeps-its-fill', async ({ + page, + }) => { + test.setTimeout(90000); + const conversationId = await seedChat('Default avatar'); + await installThemeBridge(page, null); + await failUserAvatar(page); + + try { + for (const [mode, placeholder, ink] of [ + ['light', defaultTheme['rgb-surface-secondary'], 'rgb(33, 33, 33)'], + ['dark', darkTheme['rgb-surface-tertiary'], 'rgb(236, 236, 236)'], + ] as const) { + await page.goto(`/c/${conversationId}?${THEME_PARAM}=${mode}`); + await expect(page.getByText(REPLY_TEXT, { exact: true }).first()).toBeVisible({ + timeout: 20000, + }); + + expect(await navAvatarPaint(page)).toEqual({ fill: 'rgb(121, 137, 255)', ink }); + expect(await themeValue(page, '--avatar-placeholder')).toBe(placeholder); + } + } finally { + await deleteConversations([conversationId]); + } + }); + + test('the ClickHouse definition paints the default avatar from Click UI @scenario:clickhouse-avatar-follows-click-ui', async ({ + page, + }) => { + test.setTimeout(90000); + const conversationId = await seedChat('ClickHouse avatar'); + await installThemeBridge(page, clickHouseTheme); + await failUserAvatar(page); + + try { + for (const mode of MODES) { + const colors = colorsFor(mode); + await page.goto(`/c/${conversationId}?${THEME_PARAM}=${mode}`); + await expect(page.getByText(REPLY_TEXT, { exact: true }).first()).toBeVisible({ + timeout: 20000, + }); + await expect(page.locator('html')).toHaveAttribute('data-theme', 'clickhouse'); + + expect(await navAvatarPaint(page)).toEqual({ + fill: rgbCss(colors['rgb-avatar-fill']), + ink: rgbCss(colors['rgb-avatar-text']), + }); + expect(await themeValue(page, '--avatar-placeholder')).toBe( + colors['rgb-avatar-placeholder'], + ); + } + } finally { + await deleteConversations([conversationId]); + } + }); + + test('a legacy backdrop follows a dark toggle on the document root and on a scoped root @scenario:legacy-avatar-backdrop-follows-mode', async ({ + page, + }) => { + test.setTimeout(90000); + const conversationId = await seedChat('Legacy avatar backdrop'); + await installThemeBridge(page, null); + + try { + await page.goto(`/c/${conversationId}?${THEME_PARAM}=light`); + await expect(page.getByText(REPLY_TEXT, { exact: true }).first()).toBeVisible({ + timeout: 20000, + }); + + /** What a legacy palette leaves behind: surfaces set inline, applied once in light, and a + * scoped root marked the way `applyTheme` marks one. The mode then flips with no reapply. */ + const painted = await page.evaluate(() => { + const html = document.documentElement; + const read = (node: Element) => getComputedStyle(node).backgroundColor; + const backdrop = (host: Element) => { + const node = document.createElement('div'); + node.className = 'bg-avatar-placeholder'; + host.append(node); + return node; + }; + html.classList.remove('dark'); + html.style.setProperty('--surface-secondary', '20 21 22'); + html.style.setProperty('--surface-tertiary', '30 31 32'); + const scope = document.createElement('section'); + scope.setAttribute('data-theme-scope', ''); + scope.style.setProperty('--surface-secondary', '40 41 42'); + scope.style.setProperty('--surface-tertiary', '50 51 52'); + document.body.append(scope); + const onRoot = backdrop(document.body); + const onScope = backdrop(scope); + const light = { root: read(onRoot), scoped: read(onScope) }; + html.classList.add('dark'); + const dark = { root: read(onRoot), scoped: read(onScope) }; + return { light, dark }; + }); + + expect(painted).toEqual({ + light: { root: 'rgb(20, 21, 22)', scoped: 'rgb(40, 41, 42)' }, + dark: { root: 'rgb(30, 31, 32)', scoped: 'rgb(50, 51, 52)' }, + }); + } finally { + await deleteConversations([conversationId]); + } + }); }); diff --git a/eslint-suppressions.json b/eslint-suppressions.json index 68f6bc8def..c06908c1ea 100644 --- a/eslint-suppressions.json +++ b/eslint-suppressions.json @@ -1004,7 +1004,7 @@ }, "client/src/components/Endpoints/Icon.tsx": { "shadcn/no-inline-styles": { - "count": 2 + "count": 1 } }, "client/src/components/Endpoints/MessageEndpointIcon.tsx": { @@ -1490,7 +1490,7 @@ }, "client/src/components/Share/MessageIcon.tsx": { "shadcn/no-inline-styles": { - "count": 2 + "count": 1 } }, "client/src/components/Share/MessagesView.tsx": { @@ -2203,7 +2203,7 @@ }, "packages/client/src/components/Avatar.tsx": { "shadcn/no-inline-styles": { - "count": 3 + "count": 2 } }, "packages/client/src/components/Badge.tsx": { diff --git a/packages/client/src/components/Avatar.tsx b/packages/client/src/components/Avatar.tsx index 1f70032d40..b1ae4805aa 100644 --- a/packages/client/src/components/Avatar.tsx +++ b/packages/client/src/components/Avatar.tsx @@ -51,12 +51,11 @@ const Avatar: React.FC = ({ () => (