Skip to content

fix(tailwind): load tailwind.config.js via @config - #2628

Open
camielvs wants to merge 1 commit into
masterfrom
fix/tailwind-config-directive
Open

fix(tailwind): load tailwind.config.js via @config#2628
camielvs wants to merge 1 commit into
masterfrom
fix/tailwind-config-directive

Conversation

@camielvs

Copy link
Copy Markdown
Collaborator

tailwind.config.js has been dead since the v4 upgrade. Tailwind v4 is CSS-first and does not
auto-load a JS config — it only reads one when a stylesheet asks for it with @config. src/styles/global.css
never did, so the theme.extend.fontSize entries in that file were never registered and text-2xs /
text-3xs compiled to nothing.

  @import "tailwindcss";

+ @config "../../tailwind.config.js";
+
  @plugin "tailwindcss-animate";

Proof the directive takes effect

A byte-identical build is ambiguous on its own — it is also what a silently-ignored directive looks
like. So I added a probe usage (className="… text-2xs text-3xs") to a real component and built the
app both ways:

.text-2xs .text-3xs
with @config font-size:.625rem font-size:.5rem
without @config not emitted not emitted

The probe was reverted; it is not part of this diff.

Proof nothing changes today

No file under src uses text-2xs or text-3xs — zero occurrences. With the probe removed, the built
stylesheet is byte-identical to master:

master:      161,345 bytes
this branch: 161,345 bytes   (cmp: identical)

That also settles the one real risk in loading a legacy config: its content: ["./src/**/*.{js,jsx,ts,tsx}"]
key narrows source detection from v4's automatic scanning. Identical output over a full app build means
no currently-used class lives outside that glob. Worth knowing if a class is ever added to a .html,
.mdx, or .mjs file — it would need adding to content.

Why @config rather than moving the values into @theme

Chosen per request. The alternative — deleting tailwind.config.js and adding --text-2xs: 0.625rem /
--text-3xs: 0.5rem to the existing @theme inline block — would be the more idiomatic v4 shape and
would leave one place to look for theme values instead of two. Happy to switch if preferred.

Context

Found while reviewing #2624, which independently discovered the same class of bug: text-md and
font-regular in typography.tsx also emit no CSS, because --text-md and --font-weight-regular are
not defined either. That one is a separate issue — those variants are referenced by every <Text> in the
app, so defining them would change rendered output, unlike this change.

Reviewer checklist

  • Agree @config is the direction, rather than folding the two steps into @theme inline
  • Sanity-check that a legacy content glob is acceptable (see above)

Validation

  • pnpm vite build ✅ — output byte-identical to master
  • pnpm prettier --check src/styles/global.css

Tailwind v4 does not read tailwind.config.js unless a CSS file asks for
it, so the theme.extend.fontSize entries in that file had never been
registered: text-2xs and text-3xs compiled to nothing.

Verified by building the app twice — with the directive the compiler emits
.text-2xs{font-size:.625rem} and .text-3xs{font-size:.5rem} for a probe
usage; without it, neither rule appears.

No call site uses either class today, so the emitted CSS is byte-identical
to master (161,345 bytes both ways). This only makes the two steps
available; nothing changes size.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@camielvs
camielvs requested a review from a team as a code owner August 13, 2026 22:46
@github-actions

Copy link
Copy Markdown

🎩 Preview

A preview build has been created at: fix/tailwind-config-directive/32b08bd

@morgan-wowk morgan-wowk left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 Agent review. Correct and byte-identical output today; one latent footgun worth weighing (inline).

Comment thread src/styles/global.css
@@ -1,5 +1,7 @@
@import "tailwindcss";

@config "../../tailwind.config.js";

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 @config correctly loads the otherwise-dead tailwind.config.js (verified: no postcss config, nothing else references it, the path resolves, and tailwind 4.3.2 supports @config). Caveat: the legacy content glob in that config pins source detection to src/**/*.{js,jsx,ts,tsx}, so any class authored outside that glob (e.g. index.html, an .mjs/.mdx) will silently fail to compile — a review-invisible visual-regression class. And it currently only feeds text-2xs/text-3xs, which have zero usages in src. The v4-idiomatic alternative — moving those two values into the existing @theme inline block as --text-2xs/--text-3xs — avoids reintroducing a content array entirely. Worth considering instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants