Skip to content

Commit 051fdba

Browse files
Reference imports should not generate utilities
1 parent 85da88f commit 051fdba

File tree

3 files changed

+44
-4
lines changed

3 files changed

+44
-4
lines changed

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10-
- Nothing yet!
10+
### Fixed
11+
12+
- Ensure `@import "…" reference` never generates utilities ([#15307](https://github.com/tailwindlabs/tailwindcss/pull/15307))
1113

1214
## [4.0.0-beta.5] - 2024-12-04
1315

packages/tailwindcss/src/index.test.ts

+29
Original file line numberDiff line numberDiff line change
@@ -3138,6 +3138,35 @@ describe('`@import "…" reference`', () => {
31383138
`)
31393139
})
31403140

3141+
test('does not generate utilities', async () => {
3142+
let loadStylesheet = async (id: string, base: string) => {
3143+
if (id === './foo/baz.css') {
3144+
return {
3145+
content: css`
3146+
@tailwind utilities;
3147+
`,
3148+
base: '/root/foo',
3149+
}
3150+
}
3151+
return {
3152+
content: css`
3153+
@import './foo/baz.css';
3154+
`,
3155+
base: '/root/foo',
3156+
}
3157+
}
3158+
3159+
await expect(
3160+
compileCss(
3161+
`
3162+
@import './foo/bar.css' reference;
3163+
`,
3164+
['underline'],
3165+
{ loadStylesheet },
3166+
),
3167+
).resolves.toBe('')
3168+
})
3169+
31413170
test('removes styles when the import resolver was handled outside of Tailwind CSS', async () => {
31423171
await expect(
31433172
compileCss(

packages/tailwindcss/src/index.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -388,9 +388,18 @@ async function parseCss(
388388
return WalkAction.Skip
389389
}
390390

391-
// Other at-rules, like `@media`, `@supports`, or `@layer` should
392-
// be recursively traversed as these might be inserted by the
393-
// `@import` resolution.
391+
case '@media':
392+
case '@supports':
393+
case '@layer': {
394+
// These rules should be recursively traversed as these might be
395+
// inserted by the `@import` resolution.
396+
return
397+
}
398+
399+
default: {
400+
replaceWith([])
401+
return WalkAction.Skip
402+
}
394403
}
395404
})
396405
node.nodes = [contextNode({ reference: true }, node.nodes)]

0 commit comments

Comments
 (0)