Skip to content

Merge user resolve.conditions in @tailwindcss/vite CSS @import resolver - #20499

Open
Dextheking1 wants to merge 1 commit into
tailwindlabs:mainfrom
Dextheking1:fix/vite-plugin-resolve-conditions
Open

Dextheking1 wants to merge 1 commit into
tailwindlabs:mainfrom
Dextheking1:fix/vite-plugin-resolve-conditions

Conversation

@Dextheking1

Copy link
Copy Markdown

Fixes #20426.

Summary

@tailwindcss/vite resolves CSS @import with a custom Vite resolver. That resolver spread the user's resolve config but then overwrote conditions with a hardcoded list (['style', 'development|production']), so user-configured resolve.conditions were silently dropped for CSS @import even though they were honoured for JS imports. This happened in both resolver branches (legacy pre-Environment-API and Environment API).

The fix merges instead of overwrites:

conditions: ['style', 'development|production', ...(config!.resolve.conditions ?? [])]

so the built-in conditions keep priority while user conditions still apply.

Test plan

  • Added regression tests in integrations/vite/resolvers.test.ts covering both resolver branches: vite ^8 (Environment API) and vite ^5.3.5 (legacy). A fixture package exposes ./custom.css under a my-custom-condition export and ./default.css under style/default; with resolve.conditions: ['my-custom-condition'] the built CSS must contain the custom-condition rule. 2/2 new tests pass; full vite/resolvers.test.ts: 15/15 pass.
  • Verified with the real Vite 8 resolver using the exact option shapes: old shape resolved default.css (bug reproduced), new shape resolves custom.css (fixed).
  • Prettier clean on both changed files; tsc reports 0 errors in the changed file (remaining 39 errors elsewhere in the monorepo are pre-existing environmental issues unrelated to this change).

Note: the fixture includes @import 'tailwindcss'; in the test CSS (with an explanatory comment) because the plugin returns early for files without Tailwind features, so the resolver under test would never run otherwise.

@tailwindcss/vite built its CSS @import resolver by spreading the user's
resolve config and then overwriting conditions with a hardcoded list,
silently discarding custom conditions (e.g. monorepo 'source' conditions).
The JS resolver already inherited config.resolve as-is, so the two
resolvers disagreed about which copy of a package to load.

Append the user's resolve.conditions to the built-in CSS conditions
instead of replacing them, in both the pre-Environment-API branch and the
Environment API branch. Includes a regression test covering both branches.
@Dextheking1
Dextheking1 requested a review from a team as a code owner September 19, 2026 23:07
@coderabbitai

coderabbitai Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Advanced

Run ID: ff18815c-3019-4e25-ad4a-0bcfdfde04ad

📥 Commits

Reviewing files that changed from the base of the PR and between 41d9cae and 5a7e9bc.

📒 Files selected for processing (2)
  • integrations/vite/resolvers.test.ts
  • packages/@tailwindcss-vite/src/index.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 9 remain after this review.


Walkthrough

The Vite plugin now appends user-provided resolve.conditions to the built-in CSS resolver conditions in both the legacy and Environment API paths. A parameterized integration test covers Vite ^8 and ^5.3.5 and verifies that a custom conditional CSS export is selected.

Priority: ➖ Normal

Severity of issue fixed: Medium

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Description check ✅ Passed The description clearly explains the bug, the fix, the affected resolver branches, and the regression tests. It directly matches the changeset and objectives.
Title check ✅ Passed The title clearly and concisely describes the main change: merging user-provided Vite resolve conditions in the CSS import resolver.
Linked Issues check ✅ Passed The pull request satisfies issue #20426. In packages/@tailwindcss-vite/src/index.ts, the legacy resolver appends config.resolve.conditions after style and development|production. The Environme…
Out of Scope Changes check ✅ Passed The changes stay within issue #20426. The source changes modify only CSS resolver condition merging in the two supported resolver branches. The added test changes verify this behavior. No unrelated pr…

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@greptile-apps

greptile-apps Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge; the implementation is narrowly scoped and both supported resolver paths have meaningful regression coverage.

Reviews (1) · Last reviewed commit: "fix(vite): merge user resolve.conditions..."

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.

@tailwindcss/vite discards resolve.conditions when resolving CSS @import, but honours them for JS

1 participant