Skip to content

Ensure polyfills exist after external @import at-rules #17490

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

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`\`@import 'tailwindcss'\` is replaced with the generated CSS 1`] = `
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-font-weight: initial;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-font-weight: initial;
}
}
}
}
Expand Down
36 changes: 19 additions & 17 deletions packages/tailwindcss/src/__snapshots__/index.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`compiling CSS > \`@tailwind utilities\` is replaced by utilities using the default theme 1`] = `
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-shadow: 0 0 #0000;
--tw-shadow-color: initial;
--tw-shadow-alpha: 100%;
--tw-inset-shadow: 0 0 #0000;
--tw-inset-shadow-color: initial;
--tw-inset-shadow-alpha: 100%;
--tw-ring-color: initial;
--tw-ring-shadow: 0 0 #0000;
--tw-inset-ring-color: initial;
--tw-inset-ring-shadow: 0 0 #0000;
--tw-ring-inset: initial;
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-offset-shadow: 0 0 #0000;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-shadow: 0 0 #0000;
--tw-shadow-color: initial;
--tw-shadow-alpha: 100%;
--tw-inset-shadow: 0 0 #0000;
--tw-inset-shadow-color: initial;
--tw-inset-shadow-alpha: 100%;
--tw-ring-color: initial;
--tw-ring-shadow: 0 0 #0000;
--tw-inset-ring-color: initial;
--tw-inset-ring-shadow: 0 0 #0000;
--tw-ring-inset: initial;
--tw-ring-offset-width: 0px;
--tw-ring-offset-color: #fff;
--tw-ring-offset-shadow: 0 0 #0000;
}
}
}
}
Expand Down
90 changes: 54 additions & 36 deletions packages/tailwindcss/src/__snapshots__/utilities.test.ts.snap
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`border-* 1`] = `
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
}
}
}
}
Expand Down Expand Up @@ -175,10 +177,12 @@ exports[`border-* 1`] = `
`;

exports[`border-b-* 1`] = `
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
}
}
}
}
Expand Down Expand Up @@ -349,10 +353,12 @@ exports[`border-b-* 1`] = `
`;

exports[`border-e-* 1`] = `
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
}
}
}
}
Expand Down Expand Up @@ -523,10 +529,12 @@ exports[`border-e-* 1`] = `
`;

exports[`border-l-* 1`] = `
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
}
}
}
}
Expand Down Expand Up @@ -697,10 +705,12 @@ exports[`border-l-* 1`] = `
`;

exports[`border-r-* 1`] = `
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
}
}
}
}
Expand Down Expand Up @@ -871,10 +881,12 @@ exports[`border-r-* 1`] = `
`;

exports[`border-s-* 1`] = `
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
}
}
}
}
Expand Down Expand Up @@ -1045,10 +1057,12 @@ exports[`border-s-* 1`] = `
`;

exports[`border-t-* 1`] = `
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
}
}
}
}
Expand Down Expand Up @@ -1219,10 +1233,12 @@ exports[`border-t-* 1`] = `
`;

exports[`border-x-* 1`] = `
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
}
}
}
}
Expand Down Expand Up @@ -1393,10 +1409,12 @@ exports[`border-x-* 1`] = `
`;

exports[`border-y-* 1`] = `
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-border-style: solid;
}
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions packages/tailwindcss/src/ast.ts
Original file line number Diff line number Diff line change
Expand Up @@ -582,18 +582,22 @@ export function optimizeAst(
}

if (fallbackAst.length > 0) {
let firstNonCommentIndex = newAst.findIndex((item) => item.kind !== 'comment')
if (firstNonCommentIndex === -1) firstNonCommentIndex = 0
newAst.splice(
firstNonCommentIndex,
0,
atRule(
'@supports',
// We can't write a supports query for `@property` directly so we have to test for
// features that are added around the same time in Mozilla and Safari.
'((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b))))',
[rule('@layer base', fallbackAst)],
),
// Inject `@layer __tw-properties;` at the top, such that external
// `@import url(…)` can still be placed after it.
newAst.unshift(atRule('@layer', '__tw-properties'))

// Inject the `@layer __tw-properties { … }` at the end with all the
// fallbacks.
newAst.push(
atRule('@layer', '__tw-properties', [
atRule(
'@supports',
// We can't write a supports query for `@property` directly so we have to test for
// features that are added around the same time in Mozilla and Safari.
'((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b))))',
[rule('@layer base', fallbackAst)],
),
]),
)
}
}
Expand Down
17 changes: 10 additions & 7 deletions packages/tailwindcss/src/compat/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -322,13 +322,7 @@ describe('theme callbacks', () => {

expect(compiler.build(['leading-base', 'leading-md', 'leading-xl', 'prose']))
.toMatchInlineSnapshot(`
"@supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) {
@layer base {
*, ::before, ::after, ::backdrop {
--tw-leading: initial;
}
}
}
"@layer __tw-properties;
.prose {
[class~=lead-base] {
font-size: 100rem;
Expand All @@ -355,6 +349,15 @@ describe('theme callbacks', () => {
--tw-leading: 201rem;
line-height: 201rem;
}
@layer __tw-properties {
@supports ((-webkit-hyphens: none) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color:rgb(from red r g b)))) {
@layer base {
*, ::before, ::after, ::backdrop {
--tw-leading: initial;
}
}
}
}
@property --tw-leading {
syntax: "*";
inherits: false;
Expand Down
10 changes: 6 additions & 4 deletions packages/tailwindcss/src/important.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,10 +101,12 @@ test('variables in utilities should not be marked as important', async () => {
['ease-out!', 'z-10!'],
),
).toMatchInlineSnapshot(`
"@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-ease: initial;
"@layer __tw-properties {
@supports (((-webkit-hyphens: none)) and (not (margin-trim: inline))) or ((-moz-orient: inline) and (not (color: rgb(from red r g b)))) {
@layer base {
*, :before, :after, ::backdrop {
--tw-ease: initial;
}
}
}
}
Expand Down
Loading
Loading