mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-17 21:43:06 +00:00
fix: Serialize MCP App Theme Variables as CSS Colors (#17999)
This commit is contained in:
parent
e6567c7a68
commit
f72fdaaa57
2 changed files with 47 additions and 2 deletions
|
|
@ -274,6 +274,7 @@ describe('useAppBridge', () => {
|
|||
client = new QueryClient({ defaultOptions: { queries: { retry: false } } });
|
||||
document.body.innerHTML = '';
|
||||
document.documentElement.className = '';
|
||||
document.documentElement.removeAttribute('style');
|
||||
});
|
||||
|
||||
describe('ordering', () => {
|
||||
|
|
@ -1464,6 +1465,50 @@ describe('useAppBridge', () => {
|
|||
measure.mockRestore();
|
||||
});
|
||||
|
||||
it('supplies CSS colors on initialization and theme changes', async () => {
|
||||
document.documentElement.style.setProperty('--surface-primary', '255 255 255');
|
||||
document.documentElement.style.setProperty('--text-primary', '33 33 33');
|
||||
document.documentElement.style.setProperty('--border-medium', '205 205 205 / 50%');
|
||||
document.documentElement.style.setProperty('--text-warning', '#f90');
|
||||
document.documentElement.style.setProperty('--surface-secondary', 'var(--missing)');
|
||||
mountBridge(makeResource(), client);
|
||||
await flush();
|
||||
|
||||
expect(AppBridge.mock.calls.at(-1)?.[3]).toEqual({
|
||||
hostContext: expect.objectContaining({
|
||||
theme: 'light',
|
||||
styles: {
|
||||
variables: {
|
||||
'--color-background-primary': 'rgb(255 255 255)',
|
||||
'--color-text-primary': 'rgb(33 33 33)',
|
||||
'--color-border-primary': 'rgb(205 205 205 / 50%)',
|
||||
'--color-text-warning': '#f90',
|
||||
},
|
||||
},
|
||||
}),
|
||||
});
|
||||
|
||||
await act(async () => {
|
||||
document.documentElement.style.setProperty('--surface-primary', '33 33 33');
|
||||
document.documentElement.style.setProperty('--text-primary', '255 255 255');
|
||||
document.documentElement.style.removeProperty('--border-medium');
|
||||
document.documentElement.classList.add('dark');
|
||||
await Promise.resolve();
|
||||
});
|
||||
expect(latest().hostContextChanges).toEqual([
|
||||
expect.objectContaining({
|
||||
theme: 'dark',
|
||||
styles: {
|
||||
variables: {
|
||||
'--color-background-primary': 'rgb(33 33 33)',
|
||||
'--color-text-primary': 'rgb(255 255 255)',
|
||||
'--color-text-warning': '#f90',
|
||||
},
|
||||
},
|
||||
}),
|
||||
]);
|
||||
});
|
||||
|
||||
it('pushes theme changes to a live bridge', async () => {
|
||||
mountBridge(makeResource(), client);
|
||||
await flush();
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { useEffect, useId, useRef } from 'react';
|
||||
import { readThemeColor } from '@librechat/client';
|
||||
import { useQueryClient } from '@tanstack/react-query';
|
||||
import { JSONRPCMessageSchema } from '@modelcontextprotocol/sdk/types.js';
|
||||
import { QueryKeys, DEFAULT_MCP_APP_ACTION_PREVIEW_CHARS } from 'librechat-data-provider';
|
||||
|
|
@ -138,10 +139,9 @@ function readHostTheme(): 'light' | 'dark' {
|
|||
}
|
||||
|
||||
function buildHostStyleVariables(): McpUiStyles {
|
||||
const computed = getComputedStyle(document.documentElement);
|
||||
const variables: Partial<Record<McpUiStyleVariableKey, string>> = {};
|
||||
for (const [specVar, lcVar] of Object.entries(HOST_STYLE_VAR_MAP)) {
|
||||
const value = computed.getPropertyValue(lcVar).trim();
|
||||
const value = readThemeColor(lcVar);
|
||||
if (value) {
|
||||
variables[specVar as McpUiStyleVariableKey] = value;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue