Skip to content

Commit 0d5e2be

Browse files
authored
Ensure we process Tailwind CSS features when using @reference (#16057)
This PR fixes an issue where if you only used `@reference` that we didn't process Tailwind CSS features. We have a 'quick bail check', in the PostCSS plugin to quickly bail if we _konw_ that we don't need to handle any Tailwind CSS features. This is useful in Next.js applications where every single CSS file will be passed to the PostCSS plugin. If you use custom font ins Next.js, each of those fonts will have a CSS file as well. Before we introduced `@reference`, we used `@import "tailwindcss" reference`, which passed the bail check because `@import` was being used. Now we have `@reference` which wasn't included in the list. This is now solved. Fixes: #16056 ### Test plan Added a failing test that is now failing after the fix.
1 parent ea24995 commit 0d5e2be

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010
### Fixed
1111

1212
- Only generate positive `grid-cols-*` and `grid-rows-*` utilities ([#16020](https://github.com/tailwindlabs/tailwindcss/pull/16020))
13+
- Ensure we process Tailwind CSS features when only using `@reference` or `@variant` ([#16057](https://github.com/tailwindlabs/tailwindcss/pull/16057))
1314

1415
## [4.0.1] - 2025-01-29
1516

packages/@tailwindcss-postcss/src/index.test.ts

+50
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,56 @@ test('bail early when Tailwind is not used', async () => {
248248
`)
249249
})
250250

251+
test('handle CSS when only using a `@reference` (we should not bail early)', async () => {
252+
let processor = postcss([
253+
tailwindcss({ base: `${__dirname}/fixtures/example-project`, optimize: { minify: false } }),
254+
])
255+
256+
let result = await processor.process(
257+
css`
258+
@reference "tailwindcss/theme.css";
259+
260+
.foo {
261+
@variant md {
262+
bar: baz;
263+
}
264+
}
265+
`,
266+
{ from: inputCssFilePath() },
267+
)
268+
269+
expect(result.css.trim()).toMatchInlineSnapshot(`
270+
"@media (width >= 48rem) {
271+
.foo {
272+
bar: baz;
273+
}
274+
}"
275+
`)
276+
})
277+
278+
test('handle CSS when using a `@variant` using variants that do not rely on the `@theme`', async () => {
279+
let processor = postcss([
280+
tailwindcss({ base: `${__dirname}/fixtures/example-project`, optimize: { minify: false } }),
281+
])
282+
283+
let result = await processor.process(
284+
css`
285+
.foo {
286+
@variant data-is-hoverable {
287+
bar: baz;
288+
}
289+
}
290+
`,
291+
{ from: inputCssFilePath() },
292+
)
293+
294+
expect(result.css.trim()).toMatchInlineSnapshot(`
295+
".foo[data-is-hoverable] {
296+
bar: baz;
297+
}"
298+
`)
299+
})
300+
251301
test('runs `Once` plugins in the right order', async () => {
252302
let before = ''
253303
let after = ''

packages/@tailwindcss-postcss/src/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
7777
root.walkAtRules((node) => {
7878
if (
7979
node.name === 'import' ||
80+
node.name === 'reference' ||
8081
node.name === 'theme' ||
82+
node.name === 'variant' ||
8183
node.name === 'config' ||
8284
node.name === 'plugin' ||
8385
node.name === 'apply'

0 commit comments

Comments
 (0)