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

Improve nesting detection #6011

Merged
merged 1 commit into from
Nov 10, 2021
Merged

Improve nesting detection #6011

merged 1 commit into from
Nov 10, 2021

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Nov 8, 2021

This PR improves the nesting detection.

Currently we only detected rules inside of rules, and if we did then we would trigger a PostCSS warning.

However, some people try to do something like this:

.namespace {
  @tailwind base;
  @tailwind components;
  @tailwind utilities;
}

While in theory this could work~ish, this is not something we support. The biggest reason is that base styles (and thus also the preflight/reset) would end up looking like this: .namespace html {} for example which doesn't make much sense.

This PR also detects @tailwind at rules, with a parent that is not of type root and shows a similar message:

Nested @tailwind rules detected, instead try to use a prefix: https://tailwindcss.com/docs/configuration#prefix or scope it using the important selector strategy https://tailwindcss.com/docs/configuration#selector-strategy

(@reinink can you double check the wording used in the message? Or do we keep it as is and improve all warning messages before v3 launch?)

@RobinMalfait RobinMalfait changed the title improve nesting detection Improve nesting detection Nov 8, 2021
@reinink
Copy link
Member

reinink commented Nov 9, 2021

Here are some ideas.

First, for nested Tailwind at-rules:

warn - Nested @tailwind rules were detected, but are not supported.
warn - Consider using a prefix to scope Tailwind's classes: https://tailwindcss.com/docs/configuration#prefix
warn - Alternatively, use the important selector strategy: https://tailwindcss.com/docs/configuration#selector-strategy

And for just plain nesting:

warn - Nested CSS was detected, but CSS nesting has not been configured correctly.
warn - Please enable a CSS nesting plugin *before* Tailwind in your configuration.
warn - See how here: https://tailwindcss.com/docs/using-with-preprocessors#nesting

@RobinMalfait
Copy link
Member Author

Thanks @reinink, I'll merge this with the provided changes. If we need further cleanup in warning messages (which we probably will if we want to add links to documentation pages).

@RobinMalfait RobinMalfait merged commit 4e21639 into master Nov 10, 2021
@RobinMalfait RobinMalfait deleted the improve-nesting-detection branch November 10, 2021 12:15
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.

2 participants