Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
56883e7
WIP
philipp-spiess Mar 26, 2025
747dacf
Do what needs to be done
philipp-spiess Mar 27, 2025
40ba52b
Improve Next.js playground
philipp-spiess Mar 28, 2025
5183f44
De-duplicate `lightningcss` configuration
philipp-spiess Mar 28, 2025
6937fef
Simplify `color-mix(…)` inlining and adding unit tests
philipp-spiess Mar 28, 2025
e7f48b6
Revert changes to tsconfig
philipp-spiess Mar 28, 2025
19e4beb
Update snapshots
philipp-spiess Mar 28, 2025
f3e2993
Make the `@property` stuff disable-able
philipp-spiess Mar 28, 2025
1460365
PostCSS should not polyfill `@property` for CSS module files
philipp-spiess Mar 28, 2025
f6f78b1
Update more snapshots
philipp-spiess Mar 28, 2025
4c01e6f
Update snapshots
philipp-spiess Mar 31, 2025
74c5cef
Emit `@property` fallbacks at the beginning of the file
philipp-spiess Mar 31, 2025
eb801de
Add test case to stuff
philipp-spiess Mar 31, 2025
77eb998
Update snapshots
philipp-spiess Mar 31, 2025
e4ecce7
Refactor `replaceShadowColors(…)` to print AST
philipp-spiess Mar 31, 2025
9bddc09
Add fallbacks for new relative color usage
philipp-spiess Mar 31, 2025
8f09cac
More snapshot updates and comments
philipp-spiess Mar 31, 2025
5be1398
Don't use regex for replacement
philipp-spiess Mar 31, 2025
78e10dc
Further reduce the precision of color values because lightningcss pre…
philipp-spiess Mar 31, 2025
cbcf42a
Fix regex
philipp-spiess Mar 31, 2025
0ad7aad
Fix Svelte tests
philipp-spiess Mar 31, 2025
0bbcd09
Still needs a layer and fix supports query
philipp-spiess Mar 31, 2025
7d6fabc
Even more snapshot updates
philipp-spiess Mar 31, 2025
66c2c48
So. Many. Snapshots
philipp-spiess Mar 31, 2025
ddace46
Apply cleanups and also flag `color-mix(…)` polyfills so they aren't …
philipp-spiess Apr 1, 2025
8e54832
Revert changes to `replaceShadowColors(…)` and move polyfill closer t…
philipp-spiess Apr 1, 2025
79144ce
Update color values in `colors.ts`
philipp-spiess Apr 1, 2025
9244037
Update snapshots
philipp-spiess Apr 1, 2025
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
Prev Previous commit
Next Next commit
PostCSS should not polyfill @property for CSS module files
  • Loading branch information
philipp-spiess committed Apr 1, 2025
commit 14603652d0d0e916f40a26733bde05b1d26df308
8 changes: 5 additions & 3 deletions integrations/postcss/next.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ test(
'app/page.module.css': css`
@reference './globals.css';
.heading {
@apply text-red-500 animate-ping;
@apply text-red-500 animate-ping skew-7;
}
`,
'app/globals.css': css`
Expand Down Expand Up @@ -77,9 +77,10 @@ test(
])

await fs.expectFileToContain(moduleCss!, [
'color:var(--color-red-500,oklch(.637 .237 25.331)',
'color:var(--color-red-500,oklch(63.7% .237 25.331)',
'animation:var(--animate-ping,ping 1s cubic-bezier(0,0,.2,1) infinite)',
/@keyframes page_ping.*{75%,to{transform:scale\(2\);opacity:0}/,
'--tw-skew-x:skewX(7deg);',
])
},
)
Expand Down Expand Up @@ -130,7 +131,7 @@ describe.each(['turbo', 'webpack'])('%s', (bundler) => {
'app/page.module.css': css`
@reference './globals.css';
.heading {
@apply text-red-500 animate-ping content-['module'];
@apply text-red-500 animate-ping skew-7 content-['module'];
}
`,
'app/globals.css': css`
Expand Down Expand Up @@ -173,6 +174,7 @@ describe.each(['turbo', 'webpack'])('%s', (bundler) => {
let css = await fetchStyles(url)
expect(css).toContain(candidate`underline`)
expect(css).toContain(candidate`bg-red-500`)
expect(css).toContain('--tw-skew-x: skewX(7deg);')
expect(css).toContain('content: var(--tw-content)')
expect(css).toContain('@keyframes')
})
Expand Down
6 changes: 5 additions & 1 deletion packages/@tailwindcss-node/src/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,29 @@ import {
compile as _compile,
compileAst as _compileAst,
Features,
Polyfills,
} from 'tailwindcss'
import type { AstNode } from '../../tailwindcss/src/ast'
import { getModuleDependencies } from './get-module-dependencies'
import { rewriteUrls } from './urls'

export { Features }
export { Features, Polyfills }

export type Resolver = (id: string, base: string) => Promise<string | false | undefined>

export interface CompileOptions {
base: string
onDependency: (path: string) => void
shouldRewriteUrls?: boolean
polyfills?: Polyfills

customCssResolver?: Resolver
customJsResolver?: Resolver
}

function createCompileOptions({
base,
polyfills,
onDependency,
shouldRewriteUrls,

Expand All @@ -37,6 +40,7 @@ function createCompileOptions({
}: CompileOptions) {
return {
base,
polyfills,
async loadModule(id: string, base: string) {
return loadModule(id, base, onDependency, customJsResolver)
},
Expand Down
6 changes: 6 additions & 0 deletions packages/@tailwindcss-postcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {
Features,
Instrumentation,
optimize as optimizeCss,
Polyfills,
} from '@tailwindcss/node'
import { clearRequireCache } from '@tailwindcss/node/require-cache'
import { Scanner } from '@tailwindcss/oxide'
Expand Down Expand Up @@ -72,6 +73,7 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
using I = new Instrumentation()

let inputFile = result.opts.from ?? ''
let isCSSModuleFile = inputFile.endsWith('.module.css')

DEBUG && I.start(`[@tailwindcss/postcss] ${relative(base, inputFile)}`)

Expand Down Expand Up @@ -119,6 +121,10 @@ function tailwindcss(opts: PluginOptions = {}): AcceptedPlugin {
onDependency: (path) => {
context.fullRebuildPaths.push(path)
},
// In CSS Module files, we have to disable the `@property` polyfill since these will
// emit global `*` rules which are considered to be non-pure and will cause builds
// to fail.
polyfills: isCSSModuleFile ? Polyfills.All ^ Polyfills.AtProperty : Polyfills.All,
})
DEBUG && I.end('Create compiler')

Expand Down
4 changes: 2 additions & 2 deletions packages/tailwindcss/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ export function optimizeAst(
// Collect fallbacks for `@property` rules for Firefox support
// We turn these into rules on `:root` or `*` and some pseudo-elements
// based on the value of `inherits``
if (polyfills & Polyfills.PolyfillAtProperty) {
if (polyfills & Polyfills.AtProperty) {
let property = node.params
let initialValue = null
let inherits = false
Expand Down Expand Up @@ -556,7 +556,7 @@ export function optimizeAst(
}

// Fallbacks
if (polyfills & Polyfills.PolyfillAtProperty) {
if (polyfills & Polyfills.AtProperty) {
{
let fallbackAst = []

Expand Down
4 changes: 2 additions & 2 deletions packages/tailwindcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ export const enum Polyfills {
None = 0,

// Control if fallbacks for `@property` rules are emitted
PolyfillAtProperty = 1 << 0,
AtProperty = 1 << 0,

// Enable all
All = PolyfillAtProperty,
All = AtProperty,
}

type CompileOptions = {
Expand Down
4 changes: 3 additions & 1 deletion playgrounds/nextjs/app/page.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@reference "./globals.css";

.heading {
color: var(--color-red-500);
@apply skew-7;
}