Skip to content

Conversation

@RobinMalfait
Copy link
Member

This PR fixes an issue where the combining source(…) and layer(…) didn't work well together.

@import "tailwindcss/utilities" layer(utilities);

and

@import "tailwindcss/utilities" source(none);

Worked well individually, but together they did not:

@import "tailwindcss/utilities" layer(utilities) source(none);

This is because when we handled the @import, if you see a layer(…), the import handling already converts it to:

@layer utilities {
  /* Contents of the imported file */
} 

However, if you have multiple params, it would be converted to:

@media layer(utilities) source(none) {
  /* Contents of the imported file */
} 

In this case, we never handled the @media layer(…) case correctly and we have to make sure to convert it to an @layer utilities {…} ourselves.

If it was _just_ `@import "foo" layer(…)`, then the import handling
converted the `@media layer(…)` to `@layer …` already.

But if there are more properties than that's not the case
@RobinMalfait RobinMalfait requested a review from a team as a code owner November 22, 2024 10:04
@philipp-spiess
Copy link
Member

However, if you have multiple params, it would be converted to:

@media layer(utilities) source(none) {
/* Contents of the imported file */
}

This seems like a bug in the at-import code then, no?

Layer's are supposed to be extracted into this way and it should instead create:

@layer (utilities) {
  @media source(none) {
    /* Contents of the imported file */
  }
}

https://developer.mozilla.org/en-US/docs/Web/CSS/@import#syntax

Copy link
Member

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR only fixes

@import 'tailwindcss/utilities' source('./paths') layer(utilities);

and not

@import 'tailwindcss/utilities' layer(utilities) source('./paths');

I think 🙈 I think it's fine to require layer to be the first part as per the at-import spec though, but there is still a bug in the at-import resolver 😬

@RobinMalfait
Copy link
Member Author

Ah you are right, I was thinking about that people might do this themselves or if we got this if other tools handled imports. But you are right let me fix it there instead!

Copy link
Contributor

@thecrypticace thecrypticace left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be handled in the substituteAtImports step

@philipp-spiess
Copy link
Member

Oh ignore my comment @import 'tailwindcss/utilities' layer(utilities) source('./paths'); already works, but putting source first doesn't since that's not valid css and we rely on media query propagation right now. I'll clean this up a bit so we can allow these CSS spec functions (layer and supports) at any place in the param argument list.

@philipp-spiess
Copy link
Member

Current thinking is that we do not want to support this since it won't work with third-party CSS @import resolvers (e.g. if your project depends on postcss-import or uses any sass/scss pre-processors)

This still works though, even when using a third-party import resolver:

@import 'tailwindcss/utilities' layer(utilities) source('./paths');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants