mirror of
https://github.com/tailwindlabs/tailwindcss.git
synced 2025-12-08 21:36:08 +00:00
Fixes #16725 When using `@reference "tailwindcss";` inside a separate CSS root (e.g. Svelte `<style>` components, CSS modules, etc.), we have no guarantee that the CSS variables will be defined in the main stylesheet (or if there even is one). To work around potential issues with this we decided in #16676 that we would emit all used CSS variables from the `@theme` inside the `@reference` block. However, this is not only a bit surprising but also unexpected in CSS modules and Next.js that **requires CSS module files to only create scope-able declarations**. To fix this issue, we decided to not emit CSS variables but instead ensure all `var(…)` calls we create for theme values in reference mode will simply have their fallback value added. This ensures styles work as-expected even if the root Tailwind file does not pick up the variable as being used or _if you don't add a root at all_. Furthermore we do not duplicate any variable declarations across your stylesheets and you still have the ability to change variables at runtime. ## Test plan - Updated snapshots everywhere (see diff) - New Next.js CSS modules integration test
80 lines
2.0 KiB
TypeScript
80 lines
2.0 KiB
TypeScript
import { candidate, css, html, js, json, test } from '../utils'
|
|
|
|
test(
|
|
'builds the `@headlessui/tailwindcss` plugin utilities (CJS)',
|
|
{
|
|
fs: {
|
|
'package.json': json`
|
|
{
|
|
"type": "commonjs",
|
|
"dependencies": {
|
|
"postcss": "^8",
|
|
"postcss-cli": "^10",
|
|
"tailwindcss": "workspace:^",
|
|
"@tailwindcss/postcss": "workspace:^",
|
|
"@headlessui/tailwindcss": "^0.2.1"
|
|
}
|
|
}
|
|
`,
|
|
'postcss.config.cjs': js`
|
|
let tailwindcss = require('@tailwindcss/postcss')
|
|
module.exports = {
|
|
plugins: [tailwindcss()],
|
|
}
|
|
`,
|
|
'index.html': html`
|
|
<div className="ui-open:flex"></div>
|
|
`,
|
|
'src/index.css': css`
|
|
@reference 'tailwindcss/theme';
|
|
@import 'tailwindcss/utilities';
|
|
@plugin '@headlessui/tailwindcss';
|
|
`,
|
|
},
|
|
},
|
|
async ({ fs, exec }) => {
|
|
await exec('pnpm postcss src/index.css --output dist/out.css')
|
|
|
|
await fs.expectFileToContain('dist/out.css', [candidate`ui-open:flex`])
|
|
},
|
|
)
|
|
|
|
test(
|
|
'builds the `@headlessui/tailwindcss` plugin utilities (ESM)',
|
|
{
|
|
fs: {
|
|
'package.json': json`
|
|
{
|
|
"type": "module",
|
|
"dependencies": {
|
|
"postcss": "^8",
|
|
"postcss-cli": "^10",
|
|
"tailwindcss": "workspace:^",
|
|
"@tailwindcss/postcss": "workspace:^",
|
|
"@headlessui/tailwindcss": "^0.2.1"
|
|
}
|
|
}
|
|
`,
|
|
'postcss.config.mjs': js`
|
|
import tailwindcss from '@tailwindcss/postcss'
|
|
export default {
|
|
plugins: [tailwindcss()],
|
|
}
|
|
`,
|
|
'index.html': html`
|
|
<div className="ui-open:flex"></div>
|
|
`,
|
|
'src/index.css': css`
|
|
@reference 'tailwindcss/theme';
|
|
@import 'tailwindcss/utilities';
|
|
@plugin '@headlessui/tailwindcss';
|
|
`,
|
|
},
|
|
},
|
|
async ({ fs, exec }) => {
|
|
await exec('pnpm postcss src/index.css --output dist/out.css')
|
|
|
|
await fs.expectFileToContain('dist/out.css', [candidate`ui-open:flex`])
|
|
},
|
|
)
|