Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reference imports should not generate utilities #15307

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

- Nothing yet!
### Fixed

- Ensure `@import "…" reference` never generates utilities ([#15307](https://github.com/tailwindlabs/tailwindcss/pull/15307))

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

Expand Down
11 changes: 4 additions & 7 deletions integrations/vite/svelte.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test(
target: document.body,
})
`,
'src/index.css': css`@import 'tailwindcss' reference;`,
'src/index.css': css`@import 'tailwindcss';`,
'src/App.svelte': html`
<script>
import './index.css'
Expand All @@ -58,7 +58,7 @@ test(
<h1 class="global local underline">Hello {name}!</h1>

<style>
@import 'tailwindcss/theme' theme(reference);
@import 'tailwindcss' reference;
@import './other.css';
</style>
`,
Expand Down Expand Up @@ -165,14 +165,11 @@ test(
<h1 class="local global underline">Hello {name}!</h1>

<style>
@import 'tailwindcss/theme' theme(reference);
@import 'tailwindcss' reference;
@import './other.css';
</style>
`,
'src/index.css': css`
@import 'tailwindcss/theme' theme(reference);
@import 'tailwindcss/utilities';
`,
'src/index.css': css` @import 'tailwindcss'; `,
'src/other.css': css`
.local {
@apply text-red-500;
Expand Down
2 changes: 1 addition & 1 deletion integrations/vite/vue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test(
`,
'src/App.vue': html`
<style>
@import 'tailwindcss' reference;
@import 'tailwindcss';
.foo {
@apply text-red-500;
}
Expand Down
30 changes: 30 additions & 0 deletions packages/tailwindcss/src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3138,6 +3138,36 @@ describe('`@import "…" reference`', () => {
`)
})

test('does not generate utilities', async () => {
let loadStylesheet = async (id: string, base: string) => {
if (id === './foo/baz.css') {
return {
content: css`
@layer utilities {
@tailwind utilities;
}
`,
base: '/root/foo',
}
}
return {
content: css`
@import './foo/baz.css';
`,
base: '/root/foo',
}
}

let { build } = await compile(
css`
@import './foo/bar.css' reference;
`,
{ loadStylesheet },
)

expect(build(['text-underline', 'border']).trim()).toMatchInlineSnapshot(`"@layer utilities;"`)
})

test('removes styles when the import resolver was handled outside of Tailwind CSS', async () => {
await expect(
compileCss(
Expand Down
16 changes: 13 additions & 3 deletions packages/tailwindcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,11 +388,21 @@ async function parseCss(
return WalkAction.Skip
}

// Other at-rules, like `@media`, `@supports`, or `@layer` should
// be recursively traversed as these might be inserted by the
// `@import` resolution.
case '@media':
case '@supports':
case '@layer': {
// These rules should be recursively traversed as these might be
// inserted by the `@import` resolution.
return
}

default: {
replaceWith([])
return WalkAction.Skip
}
}
})

node.nodes = [contextNode({ reference: true }, node.nodes)]
}

Expand Down