LibreChat/packages/client/tailwind.config.js
Marco Beretta 1e7b4a9bbd 🎨 feat: Check Color Tokens and Class Existence (#16041)
* 🎨 feat: Check Color Tokens and Class Existence

Moves the Tailwind colors out of createTailwindColors() and into
packages/client/src/theme/tokens.css as `@theme inline`, published as
@librechat/client/theme.css and imported by the app's stylesheet. Runtime theme
switching is unchanged: each token still resolves to the custom property
ThemeProvider rewrites, and `@theme inline` is what keeps it out of a frozen
variable. The palette scales are closed, so an undeclared shade is no longer a
color.

Reading the tokens is what lets @shadcn/lint check them, so no-unknown-classes
goes on and no-raw-colors gains undeclared-token detection. Between them they
found dead classes the app has been shipping: 59 `token-`-prefixed color
classes that generate nothing, `transition-color`, `scrollbar-hide`,
`pointer-cursor`, `mt-text-sm`, `dark:gpt-dark-gray`, `-ml-0.9`, `-mt-0.8`,
`transition-width` and `overflow-anchor-none`, all repaired or removed here.

The library's own config gains tailwindcss-animate, since its components write
`animate-in` and the accordion keyframes.

* 🧽 refactor: Delete the Plain `*-token-*` Rules the Tokens Replace

`client/src/style.css` defined `.text-token-text-{primary,secondary,tertiary}`,
`.border-token-border-{light,medium}` and `.bg-token-surface-secondary` as plain rules,
so the 63 call sites this pull request renamed were painting their token rather than
nothing. The rules have no consumer left once the names are gone, and they sat outside
`@layer utilities`, where an unlayered rule beats every utility on the same property:
keeping them would hold that cascade for any class attribute that reintroduced a name.
Deleting them is what lets the variants written beside those classes apply — the entity
avatars take `dark:bg-surface-tertiary` in dark mode, and the two action-header fields
take `hover:border-border-heavy` on hover.

Two files the rename touches carried lint debt the changed-file gate attributes to this
pull request once they appear in the diff: `ActiveSetting.tsx` was an unreferenced mock
component whose hard-coded copy fails `i18next/no-literal-string`, and `Retrieval.tsx`
computed a `vectorStores` value nothing reads. Both are removed. `tokens.spec.ts` takes
its `structuredClone` polyfill and its Tailwind module loader through imports, which
`@typescript-eslint/no-require-imports` requires of a TS file.

* ✅ test: Cover the Token Utilities From a Browser

Whether an element still takes its token color after the plain rules are gone is only
answerable in a rendered page, so the four behaviours this change turns on get a tagged
scenario in the mock harness: the account-menu email resolves `--text-secondary` instead
of inheriting the menu's primary text color, a theme definition installed at load
recolors that same row to its own value (what `@theme inline` exists for), the mention
menu's frame resolves `--border-light` rather than falling back to `currentColor`, and
the login email field transitions `color`/`border-color` for 200 ms instead of `all`,
which is what `transition-color` left it doing. Each reads the theme's custom properties
through the browser rather than restating a hex, so the same assertions hold in light
mode, dark mode and mobile emulation.

* 🩹 test: Settle the Shell Before Locating the Account Button

Probing `nav-user` visibility straight after `goto` reports the desktop sidebar as absent,
because nothing has rendered yet, and the fallback then waited on the mobile-only header
toggle until the test timed out — the two account-menu scenarios failed that way on both
desktop projects while passing on mobile. Waiting for the composer first settles the shell,
and the fallback click carries a timeout so a missing toggle fails fast instead of hanging.

* 🩹 test: Open the Drawer Before Reaching the Account Button

Below `md` the account button renders inside the drawer's own header, off-canvas until
the toggle opens it: a locator calls it visible, a click waits for it to stop moving, and
the two account-menu scenarios timed out on the mobile project. The toggle is `md:hidden`,
so its own visibility is the layout probe — click it when it is there, then the button is
reachable in both layouts.

* 📝 docs: Point the Theme Setup and the Lint Contract at What Ships

The theme README's setup still told a consumer to rebuild the color map in
`theme.extend.colors` — the map this change deletes — and never mentioned the published
stylesheet, so following it leaves the semantic utilities ungenerated. Steps 3 and 4 now
import `@librechat/client/theme.css` and the config keeps only content, dark mode and the
preset, with the removal called out as the breaking change it is.

`CLAUDE.md` said five design rules run and that `no-unknown-classes` stays off because the
repository is on Tailwind 3.4; this change enables it. That section now describes six rules,
what the rule cannot see and therefore what the `allow` list is for, that `no-raw-colors`
also reports an undeclared token, and the distinction a reviewer needs for this diff: a
raised suppression count usually means a new override, but a rule that starts resolving
class names it used to skip reports styling the tree already carried.

* 🩹 fix: Publish the Token Stylesheet as a File, Not a Folder

tsdown's `copy` reads `to` as a destination directory, so `{ from: 'src/theme/tokens.css',
to: 'dist/theme.css' }` produced `dist/theme.css/tokens.css` — a directory where the
package's `./theme.css` export pointed, which makes
`@import '@librechat/client/theme.css'` fail for every consumer of the published package.
The copy now keeps the file's name in `dist` and the export maps `./theme.css` onto
`./dist/tokens.css`; `require.resolve('@librechat/client/theme.css')` answers with that
file after a build. The app is unaffected either way, because `client/src/style.css`
imports the tokens from source so a lint or CI run needs no prior build — which is exactly
why nothing here noticed.

* 🎨 fix: Give the Bash Command Pane the Code Surface Role

Repairing `dark:bg-gray-950` by swapping in this palette's darkest shade kept the pane on a
raw value: `gray-900` is a scale entry, so no theme — custom, high contrast, or a future
one — can recolor a surface that every other code pane takes from `surface-code`
(`DiffView`, the user-turn code bars). It now takes that role in both modes, which also
drops the light/dark split the element carried for no reason.

Appearance moves with it: dark goes to `#212121` instead of `#0d0d0d`, light to `#f7f7f8`
instead of `#ececec`, matching the diff pane directly above it in the same card.

* 🩹 fix: Stop Hand-Copied Tailwind Rules From Outranking Their Utilities

`client/src/style.css` carried a block of Tailwind's own v2/v3 output copied in by
hand — `.hidden`, `.overflow-y-auto`, `.overflow-x-auto`, `.truncate`,
`.text-ellipsis`, `.animate-spin`, `.grow` and a `--tw-*`-based `.transform`. Under
v3 those sat beside the generated utilities and lost to anything later in the sheet.
Under v4 the utilities live in `@layer utilities` and these rules do not, so they beat
every utility for their property, variants included: `hidden sm:flex` and
`hidden md:flex` resolve to `display: none` at every width.

Two surfaces were gone because of it. The welcome screen's disclaimer
(`Chat/Footer.tsx`, `hidden … sm:flex`) never appeared, and the header's right-hand
control cluster (`hidden items-center gap-2 md:flex`) took the bookmark menu and the
temporary-chat toggle with it. `scenarios/welcome-disclaimer.spec.ts`,
`scenarios/temporary-chat-icon.spec.ts` and `bookmarks.spec.ts` fail on the parent
branch's build and pass here; nothing else in the style-sensitive e2e set changes.

Tailwind generates every declaration removed here, so the only behavioural difference
is `overflow: overlay`, which the copies set and which Chrome has aliased to `auto`
for years and other engines never implemented.

* 📝 docs: Load the Documented Tailwind Config From the Documented Stylesheet

v4 reads no config file unless a stylesheet says so, and the setup's step 3 imported the
tokens without an `@config` line, so the config step 4 tells a consumer to write — the
preset, the `content` globs, class-based dark mode — never applied. Both of this
repository's own entries carry the directive (`client/src/style.css`,
`packages/client/src/theme/theme.css`); the example now does too, and step 4 says that the
file only takes effect through it.

* ✅ test: Cover the Token Checks and the Published Stylesheet From a Browser

Two `@scenario`-tagged specs for what this change turned on. The first asks the
flat config, through a stdin probe, what a caller hears for a class Tailwind
cannot generate (`transition-color`) and for a colour token nobody declared
(`bg-surfce-primary`): both rules report, both name the spelling the author
meant, and the correctly spelled neighbours stay silent, which is what makes the
report about those two classes rather than about the probe. The second resolves
the `./theme.css` export the way a bundler does and asserts it lands on a file
that declares the `@theme inline` tokens and ships inside the package's `files`
— the export resolved to a directory once, and a consumer's `@import` is where
that failed.

* 🩹 fix: Record the Backlog the Rebase Brought Into the Enabled Rules

The 28 `dev` commits this stack caught up with added styling to three files the
full-tree sweep lints, and the recorded counts predate them: `ToolApproval.tsx`,
`Chat/Trace/Viewer.tsx` and the `TemplateTable.tsx` mockup reported through the
baseline, which is what the ESLint config regression gate compares. Those
violations are `dev`'s existing styling arriving in the rules' scope, so they
are recorded rather than restyled, and the count in CLAUDE.md follows.

* 🩹 fix: Ship the Animation Plugin With the Preset Consumers Load

The components published here write `animate-in`, `fade-in-0`, `zoom-in-95` and
`slide-in-from-*` — dialogs, popovers and dropdowns — and those are
`tailwindcss-animate` utilities. The plugin was registered only in
`packages/client/tailwind.config.js`, which is neither exported nor in the
package's `files`, so a consumer following the documented setup loaded the
preset and got no CSS for any of them: the surfaces appeared without their
motion and nothing said why.

The preset registers the plugin, `tailwindcss-animate` joins `tailwindcss` and
`tailwind-merge` as a peer dependency, and the consumer contract says so. The
new `@scenario:the-published-preset-generates-the-components-animations`
compiles the preset the way a consumer's build does — no app config — and
requires CSS and keyframes for each of those classes, with `p-4` as the control.

* 🩹 fix: Point the Documented Consumer Globs at the Files That Ship

Step 4 of the theme README handed a consumer
`./node_modules/@librechat/client/dist/**/*.js` as the content glob that reaches
this package. `tsdown.config.mjs` sets `fixedExtension: true`, so `dist` holds
`index.mjs` and `index.cjs` and never a `.js` — the glob matched zero files. A
consumer following the documented setup scanned only their own `src`, so every
utility that appears exclusively in a published component (dialog, menu, button
surfaces) was generated for nobody. The SPA never saw it: `client/tailwind.config.cjs`
scans `../packages/client/src`, the source, not the built package.

The glob now reads `dist/**/*.{js,mjs,cjs}`, and a scenario reads it back out of
the README rather than restating it, so the prose and the shipped file names
cannot drift apart again: it resolves the globs against the built package and
asserts they match every javascript module the export map points into `dist`,
and that those modules really do carry class names to find.

Against the previous README the same glob expansion matches `[]`; against this
one it matches `dist/index.mjs` and `dist/index.cjs`.

* 🩹 fix: Settle the Baseline, the Peer Metadata and the Comment the Rules Left

Three records that disagreed with the code they describe, all of them surfaced
by this pull request's own CI lane on a81c4a3.

`eslint-suppressions.json` recorded 10 `no-restyle` violations for
`client/src/components/Chat/AddMultiConvo.tsx` while the file has 9: the base
branch repaired one (`blur-sm` → `blur-xs` in a3e450de) without re-recording,
and this branch's baseline commit replayed the stale count over it. The
suppressions validator reads the whole baseline once the file is in the diff, so
it failed the Static Checks job with exactly that line. `npm run lint:design:prune`
drops the unused one; the trailing newline the runner strips is restored.

`package-lock.json` never received the two peers `packages/client/package.json`
declares: `tailwindcss` (added on the base branch) and `tailwindcss-animate`
(added here). The resolved tree was already correct — `tailwindcss-animate@1.0.7`
is hoisted — but the workspace entry's `peerDependencies` block disagreed with
its manifest. `npm install --package-lock-only` adds the two lines and changes
nothing else.

`eslint.config.mjs` still explained, four lines above the rule, that
`no-unknown-classes` "is deliberately not enabled" because "this repo runs
tailwindcss 3.4 with a JS preset". It is enabled at error on line 268, and the
comment beside the rule already says why that is now answerable.

* 🩹 fix: Import the Token Stylesheet Where the Consumer Probe Compiles

The standalone-consumer scenario compiled `@import 'tailwindcss'` plus the
package's config and nothing else, which is where the colours used to come from:
`createTailwindColors()` spread them into `theme.extend.colors`. They are
declared in `tokens.css` as `@theme inline` now, so that entry emitted no
`border-border-light` at all — compiled here, the class count is 0 — and the
divider fell back to `currentColor`, failing the e2e lane on shard 3 with the
text ink (`rgb(200, 0, 0)`) where the border role belongs.

The probe now imports the published token stylesheet between Tailwind and the
config, which is step 3 of the theme README and what a consumer following it
writes; the path comes from the package's own `./theme.css` export so it cannot
drift from what ships, and the build guard requires that file too. With the
import the utility compiles as
`border-color: rgb(var(--border-light) / var(--border-light-alpha, 1))`, and the
radius assertions are untouched: `rounded-sm` still resolves
`calc(var(--radius, 0.5rem) - 0.375rem)`.

The scenario joins this change's acceptance contract, because the invariant it
now protects is this one's: a consumer gets the package's colours from the
stylesheet, not from a config block.

* 🧽 refactor: Stop the Dashed Avatar Border From Depending on Emission Order

Both avatar placeholders carried `border-border-medium` and `border-black` on
one element. Same specificity, so the winner is whichever Tailwind emits last,
and compiling this tree's own config puts `.border-black` at line 3021 and
`.border-border-medium` at 3042 — the token wins today, which is why the
placeholders looked unchanged through the rename. Nothing states that order,
so a change in how Tailwind sorts utilities would silently turn the border
black.

`border-black` is deleted at both sites. The border keeps painting
`border-border-medium` exactly as it does now, and the recorded counts do not
move: neither file has a `no-raw-colors` entry, and the suppressions validator
stays green over the 74-file diff.

* 🎞️ fix: Preserve Component Animations When Integrating Canary

* 🎛️ fix: Let Shared Primitives Own Input and Tab Styling

* 🔗 fix: Preserve Auth Link Color Transitions

* 🧪 test: Verify Auth Link Color Transitions

* fix: Preserve Semantic Color Enforcement and Consumer Setup

* fix: Preserve Consumer Tailwind Palettes

* fix: Copy the Compatibility Palette Into the Docker Client Build

---------

Co-authored-by: berry-13 <berry-13@users.noreply.github.com>
(cherry picked from commit 78694f8c1e)

Original-PR: https://github.com/LibreChat-AI/LibreChat/pull/16041
2026-10-01 03:46:16 +00:00

21 lines
950 B
JavaScript

const libreChatTailwindPreset = require('./tailwind.preset.cjs');
const compatibilityColors = require('./tailwind.compat.cjs');
/**
* The library's own Tailwind config, used when developing and testing the package in isolation.
* Semantic colors are declared in `src/theme/tokens.css`, published as
* `@librechat/client/theme.css`. Legacy compatibility colors apply only inside this repository.
*
* @type {import('tailwindcss').Config}
*/
module.exports = {
content: ['./src/**/*.{js,jsx,ts,tsx}'],
darkMode: ['class'],
presets: [libreChatTailwindPreset],
theme: { extend: { colors: compatibilityColors } },
// No plugins here: the components write `animate-in`, `fade-in-0`, `slide-in-from-*` and the
// accordion keyframes, and the preset above is what registers the plugin generating them, for
// this config and for a consumer's alike. Registering it a second time emits each of those
// utilities twice.
plugins: [],
};