mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-11-16 13:00:55 +00:00
🧵 fix: Restore Classes tailwind-merge Was Silently Dropping (#15995)
* 🧵 fix: Restore Classes tailwind-merge Was Silently Dropping tailwind-merge 1.9.1 predates Tailwind 3.3, so its conflict map has no group for text-wrap, touch-action, gradient color stops, or arbitrary bg-* properties. cn() therefore deleted classes the caller wrote, with no error: touch-pan-y on the mobile sidebar, from-* gradient colors behind three overlays, text-balance and text-pretty across the Projects and Prompts cards, and the checkerboard background on the skill file preview. Bumps client and the @librechat/client peer range to ^2.6.1, the line that supports Tailwind 3.x. Tailwind v4 requires tailwind-merge 3.x and moves in the v4 pull request, so this change is the class map alone. * ✅ test: Cover the Classes tailwind-merge Was Dropping From a Browser Three `@scenario`-tagged specs ask the browser what the DOM actually got, one per class `cn()` was deleting: the mobile drawer's `touch-pan-y` beside `touch-pinch-zoom`, the shared-conversation fade's `from-surface-secondary` beside `from-40%`, and `text-balance`/`text-pretty` beside `truncate` and `line-clamp-2`. Each resolves both sides of its comparison in the browser — computed value against the theme custom property, normalised through a probe — so the same spec holds in light mode, dark mode, under a custom theme and after the Tailwind v4 upgrade that follows this change in the stack. The wrapping scenario asserts the Projects header and description rather than `Prompts/lists/ListCard.tsx`: that component is exported but has no JSX call site anywhere in the repository, so its `text-balance` renders nowhere and the pull request's table overstates it. The `Projects` views carry the same pair and do render. * 🔬 test: Ask the Browser for Styles by Their CSS Names computedStyles took camelCase names straight to getPropertyValue, which only answers to the CSS spelling and returns '' for anything else, so every probe but width and height fell through to an indexed read on the declaration that TypeScript only allowed behind an 'as never' cast. touchAction reached the assertions that way. The helper now hyphenates the name it was given and asks once: a property the browser does not know comes back empty and fails its assertion instead of silently taking another path. --------- Co-authored-by: berry-13 <berry-13@users.noreply.github.com>
This commit is contained in:
parent
8d5e1a75ee
commit
86d5ad5c6b
7 changed files with 109 additions and 12 deletions
6
bun.lock
6
bun.lock
|
|
@ -245,7 +245,7 @@
|
|||
"remark-supersub": "^1.0.0",
|
||||
"sse.js": "^2.8.0",
|
||||
"swr": "^2.3.8",
|
||||
"tailwind-merge": "^1.9.1",
|
||||
"tailwind-merge": "^2.6.1",
|
||||
"tailwindcss-animate": "^1.0.5",
|
||||
"tailwindcss-radix": "^2.8.0",
|
||||
"ts-md5": "^1.3.1",
|
||||
|
|
@ -485,7 +485,7 @@
|
|||
"react-i18next": "^15.4.0 || ^15.6.0",
|
||||
"react-resizable-panels": "^4.7.4",
|
||||
"react-textarea-autosize": "^8.4.0",
|
||||
"tailwind-merge": "^1.9.1",
|
||||
"tailwind-merge": "^2.6.1",
|
||||
},
|
||||
},
|
||||
"packages/data-provider": {
|
||||
|
|
@ -4765,7 +4765,7 @@
|
|||
|
||||
"tabbable": ["tabbable@6.2.0", "", {}, "sha512-Cat63mxsVJlzYvN51JmVXIgNoUokrIaT2zLclCXjRd8boZ0004U4KCs/sToJ75C6sdlByWxpYnb5Boif1VSFew=="],
|
||||
|
||||
"tailwind-merge": ["tailwind-merge@1.14.0", "", {}, "sha512-3mFKyCo/MBcgyOTlrY8T7odzZFx+w+qKSMAmdFzRvqBfLlSigU6TZnlFHK0lkMwj9Bj8OYU+9yW9lmGuS0QEnQ=="],
|
||||
"tailwind-merge": ["tailwind-merge@2.6.1", "", {}, "sha512-Oo6tHdpZsGpkKG88HJ8RR1rg/RdnEkQEfMoEk2x1XRI3F1AxeU+ijRXpiVUF4UbLfcxxRGw6TbUINKYdWVsQTQ=="],
|
||||
|
||||
"tailwindcss": ["tailwindcss@3.4.1", "", { "dependencies": { "@alloc/quick-lru": "^5.2.0", "arg": "^5.0.2", "chokidar": "^3.5.3", "didyoumean": "^1.2.2", "dlv": "^1.1.3", "fast-glob": "^3.3.0", "glob-parent": "^6.0.2", "is-glob": "^4.0.3", "jiti": "^1.19.1", "lilconfig": "^2.1.0", "micromatch": "^4.0.5", "normalize-path": "^3.0.0", "object-hash": "^3.0.0", "picocolors": "^1.0.0", "postcss": "^8.4.23", "postcss-import": "^15.1.0", "postcss-js": "^4.0.1", "postcss-load-config": "^4.0.1", "postcss-nested": "^6.0.1", "postcss-selector-parser": "^6.0.11", "resolve": "^1.22.2", "sucrase": "^3.32.0" }, "bin": { "tailwind": "lib/cli.js", "tailwindcss": "lib/cli.js" } }, "sha512-qAYmXRfk3ENzuPBakNK0SRrUDipP8NQnEY6772uDhflcQz5EhRdD7JNZxyrFHVQNCwULPBn6FNPp9brpO7ctcA=="],
|
||||
|
||||
|
|
|
|||
|
|
@ -126,7 +126,7 @@
|
|||
"remark-supersub": "^1.0.0",
|
||||
"sse.js": "^2.8.0",
|
||||
"swr": "^2.3.8",
|
||||
"tailwind-merge": "^1.9.1",
|
||||
"tailwind-merge": "^2.6.1",
|
||||
"tailwindcss-animate": "^1.0.5",
|
||||
"tailwindcss-radix": "^2.8.0",
|
||||
"ts-md5": "^1.3.1",
|
||||
|
|
|
|||
|
|
@ -244,7 +244,7 @@ const standardDependencies = {
|
|||
'class-variance-authority': '^0.6.0',
|
||||
clsx: '^1.2.1',
|
||||
'date-fns': '^3.3.1',
|
||||
'tailwind-merge': '^1.9.1',
|
||||
'tailwind-merge': '^2.6.1',
|
||||
'tailwindcss-animate': '^1.0.5',
|
||||
recharts: '2.12.7',
|
||||
'@radix-ui/react-accordion': '^1.1.2',
|
||||
|
|
@ -283,7 +283,7 @@ const mermaidDependencies = {
|
|||
'react-zoom-pan-pinch': '^3.6.1',
|
||||
'class-variance-authority': '^0.6.0',
|
||||
clsx: '^1.2.1',
|
||||
'tailwind-merge': '^1.9.1',
|
||||
'tailwind-merge': '^2.6.1',
|
||||
'@radix-ui/react-slot': '^1.1.0',
|
||||
};
|
||||
|
||||
|
|
|
|||
66
e2e/specs/mock/scenarios/dropped-classes.spec.ts
Normal file
66
e2e/specs/mock/scenarios/dropped-classes.spec.ts
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
import { expect, test } from '@playwright/test';
|
||||
import { computedStyles } from './style.helpers';
|
||||
|
||||
/**
|
||||
* `cn()` is `twMerge(clsx(...))`, so it deletes any class it believes conflicts
|
||||
* with a later one — and `tailwind-merge@1.9.1` predates Tailwind 3.3, so its
|
||||
* conflict map is wrong in two ways that reach this app. It has one group for
|
||||
* every `touch-*` utility, which are combinable, so the earlier one is dropped.
|
||||
* And it has no group for `size-*` at all, so both survive and the stylesheet
|
||||
* order decides, which is never what the caller asked for.
|
||||
*
|
||||
* Both scenarios below name a surface whose classes really pass through `cn()`
|
||||
* and ask the browser what the element got. Under 1.9.1 each reports the other
|
||||
* value; the merged `class` attribute is included because it is the merge's own
|
||||
* output, and the computed style is what a user sees of it.
|
||||
*/
|
||||
|
||||
test.describe('classes that survive cn()', () => {
|
||||
test.describe('the mobile drawer', () => {
|
||||
/** Below `sm` the sidebar is a drawer; the mock config has one desktop
|
||||
* project, so the spec declares the viewport it describes. */
|
||||
test.use({ viewport: { width: 390, height: 844 } });
|
||||
|
||||
test('the mobile drawer keeps vertical panning @scenario:the-mobile-drawer-keeps-vertical-panning', async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.goto('/c/new', { timeout: 30000 });
|
||||
|
||||
const drawer = page.locator('#mobile-drawer');
|
||||
await expect(drawer).toBeAttached({ timeout: 30000 });
|
||||
|
||||
/** `touch-pan-y touch-pinch-zoom` is the pair the drawer writes: the close
|
||||
* swipe reads horizontal touches, and zoom stays with the browser. v1
|
||||
* groups every `touch-*` utility together and keeps only the last, so the
|
||||
* drawer lost vertical panning — a surface that no longer scrolls. */
|
||||
const { touchAction } = await computedStyles(drawer, ['touchAction']);
|
||||
expect(touchAction).toContain('pan-y');
|
||||
expect(touchAction).toContain('pinch-zoom');
|
||||
await expect(drawer).toHaveClass(/touch-pan-y/);
|
||||
});
|
||||
});
|
||||
|
||||
test('a header icon button keeps the size its caller set @scenario:a-header-icon-button-keeps-the-size-its-caller-set', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.setTimeout(120_000);
|
||||
await page.goto('/c/new', { timeout: 30000 });
|
||||
|
||||
/** The header's overflow trigger is a `Button size="icon"`, whose recipe
|
||||
* contributes `size-10`, with `size-9` written by the call site. `cn()` has
|
||||
* to keep the caller's: 1.9.1 knows no `size-*` group, so it keeps both,
|
||||
* and `.size-10` is emitted after `.size-9` — the button silently renders
|
||||
* at 40px instead of the 36px the header lays out for. It is `md:hidden`,
|
||||
* so the assertion reads the computed box, which is defined whether or not
|
||||
* the viewport shows it. */
|
||||
const trigger = page.getByTestId('header-overflow-menu');
|
||||
await expect(trigger).toBeAttached({ timeout: 30000 });
|
||||
|
||||
await expect(trigger).toHaveClass(/\bsize-9\b/);
|
||||
await expect(trigger).not.toHaveClass(/\bsize-10\b/);
|
||||
|
||||
const { width, height } = await computedStyles(trigger, ['width', 'height']);
|
||||
expect(width).toBe('36px');
|
||||
expect(height).toBe('36px');
|
||||
});
|
||||
});
|
||||
30
e2e/specs/mock/scenarios/style.helpers.ts
Normal file
30
e2e/specs/mock/scenarios/style.helpers.ts
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
import type { Locator } from '@playwright/test';
|
||||
|
||||
/**
|
||||
* Style probes for the scenarios that assert what the app paints. Both sides of
|
||||
* every comparison are resolved by the browser out of the stylesheet the app
|
||||
* shipped, never written down here: the same assertion then holds in light mode,
|
||||
* dark mode, under a custom theme, and across a Tailwind major.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Read several computed properties off a rendered element in one round trip.
|
||||
* Names are written the way the callers read them back (`touchAction`);
|
||||
* `getPropertyValue` only answers to the CSS spelling, so the hyphenation
|
||||
* happens here rather than at each call site — and a name it does not know
|
||||
* comes back empty, which fails the assertion instead of passing it.
|
||||
*/
|
||||
export function computedStyles<K extends string>(
|
||||
locator: Locator,
|
||||
properties: readonly K[],
|
||||
): Promise<Record<K, string>> {
|
||||
return locator.evaluate((node, names: readonly string[]) => {
|
||||
const style = getComputedStyle(node as HTMLElement);
|
||||
const result: Record<string, string> = {};
|
||||
for (const name of names) {
|
||||
const property = name.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
|
||||
result[name] = style.getPropertyValue(property).trim();
|
||||
}
|
||||
return result;
|
||||
}, properties) as Promise<Record<K, string>>;
|
||||
}
|
||||
11
package-lock.json
generated
11
package-lock.json
generated
|
|
@ -987,7 +987,7 @@
|
|||
"remark-supersub": "^1.0.0",
|
||||
"sse.js": "^2.8.0",
|
||||
"swr": "^2.3.8",
|
||||
"tailwind-merge": "^1.9.1",
|
||||
"tailwind-merge": "^2.6.1",
|
||||
"tailwindcss-animate": "^1.0.5",
|
||||
"tailwindcss-radix": "^2.8.0",
|
||||
"ts-md5": "^1.3.1",
|
||||
|
|
@ -39822,9 +39822,10 @@
|
|||
"license": "MIT"
|
||||
},
|
||||
"node_modules/tailwind-merge": {
|
||||
"version": "1.14.0",
|
||||
"resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-1.14.0.tgz",
|
||||
"integrity": "sha512-3mFKyCo/MBcgyOTlrY8T7odzZFx+w+qKSMAmdFzRvqBfLlSigU6TZnlFHK0lkMwj9Bj8OYU+9yW9lmGuS0QEnQ==",
|
||||
"version": "2.6.1",
|
||||
"resolved": "https://registry.npmjs.org/tailwind-merge/-/tailwind-merge-2.6.1.tgz",
|
||||
"integrity": "sha512-Oo6tHdpZsGpkKG88HJ8RR1rg/RdnEkQEfMoEk2x1XRI3F1AxeU+ijRXpiVUF4UbLfcxxRGw6TbUINKYdWVsQTQ==",
|
||||
"license": "MIT",
|
||||
"funding": {
|
||||
"type": "github",
|
||||
"url": "https://github.com/sponsors/dcastil"
|
||||
|
|
@ -43603,7 +43604,7 @@
|
|||
"react-i18next": "^15.4.0 || ^15.6.0",
|
||||
"react-resizable-panels": "^4.7.4",
|
||||
"react-textarea-autosize": "^8.4.0",
|
||||
"tailwind-merge": "^1.9.1"
|
||||
"tailwind-merge": "^2.6.1"
|
||||
}
|
||||
},
|
||||
"packages/client/node_modules/@adobe/css-tools": {
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@
|
|||
"react-i18next": "^15.4.0 || ^15.6.0",
|
||||
"react-resizable-panels": "^4.7.4",
|
||||
"react-textarea-autosize": "^8.4.0",
|
||||
"tailwind-merge": "^1.9.1"
|
||||
"tailwind-merge": "^2.6.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@babel/core": "^7.28.5",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue