Skip to content

Commit

Permalink
Reference imports should not generate utilities
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-spiess committed Dec 5, 2024
1 parent 85da88f commit 204b444
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 4 deletions.
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
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

0 comments on commit 204b444

Please sign in to comment.