Skip to content
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

Only detect nesting when using @apply #13325

Merged
merged 7 commits into from Mar 23, 2024
Merged

Only detect nesting when using @apply #13325

merged 7 commits into from Mar 23, 2024

Conversation

RobinMalfait
Copy link
Contributor

Up until now we've detected nesting and warned our users to ensure that they're using a nesting plugin. All major browsers have proper support for native nesting so there is no need for us to keep warning the user about nested CSS at all.

However, there are still cases where nesting is not allowed and that's when you are using @apply.

If you are using @apply foo where foo contains nested CSS, then it will not work as expected, and in this scenario you do need to use a nesting plugin.

If you are using @apply and you are not applying any classes with nesting in them, then you are good to go.

Fixes: #13317

Comment on lines 445 to 446
'Please enable a CSS nesting plugin *before* Tailwind in your configuration.',
'See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting',
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This part is coming from the original detectNesting code

Copy link
Member

Choose a reason for hiding this comment

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

Can drop this part with the change above I think.

rule.walkRules(() => {
throw apply.error(
[
`The \`${applyCandidate}\` class cannot be applied because it uses nested CSS.`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a new message, so we can definitely change some wording here.

Copy link
Member

Choose a reason for hiding this comment

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

Maybe something like:

`The \`${applyCandidate}\` class cannot be used with \`@apply\` because \`@apply\` does not currently support nested CSS.`,
'Rewrite the selector without nesting or configure the `tailwindcss/nesting` plugin:',
'https://tailwindcss.com/docs/using-with-preprocessors#nesting',

}

rule.walkRules(() => {
throw apply.error(
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I used an error instead of a warning like we used to do for 2 reasons:

  1. All apply issues in this file use error.
  2. If we just warn, we would still generate incorrect code.

src/lib/expandApplyAtRules.js Show resolved Hide resolved
src/lib/expandApplyAtRules.js Show resolved Hide resolved
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.

Tailwind CSS does not work with native nested CSS
3 participants