-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Variant nodes are appended to the document rather than a root #7207
Comments
@ma-g-ma maybe this is it! and i've just been blind. can you give it a go? add if it is, tailwind people: feel free to close this. we will just have to remember to always define the variants at-rule. i'll also update our syntax's docs |
@43081j Yep, it works! Both variants are correctly placed. Though it seems that they appear with an invalid pseudo selector e.g.
IDE error messsage:
Of course, this might be unrelated. |
awesome. for tailwind maintainers: maybe its still worth warning in these situations? if someone tries to use one of your classes without specifying the at-rule, especially if they have a @ma-g-ma i'll track it in the other issue we have open and try look into it soon 👍 |
Just commenting to say that the syntax you mentioned above is correct, as you can check through the W3C CSS Validator. Are you still having that issue? |
That was a bug in the syntax FYI, backslashes not being escaped in the stringified output (it's in a string so one backslash would be nothing). It has been fixed. I don't think there's necessarily a bug here in tailwind after all. But I do think the behaviour could be improved so the user gets warned when trying to use classes without the associated directive (only if they have a Document in their AST, implying it's a custom syntax). |
The fix for this will go out in the next release. What we've opted to do for now is run Tailwind on each "root" node present in the postcss |
What version of Tailwind CSS are you using?
3.0.16
What build tool (or framework if it abstracts the build tool) are you using?
postcss-cli 9.1.0
What version of Node.js are you using?
17.x
Reproduction URL
See the reproduction in 43081j/postcss-lit#26
postcss recently introduced the concept of a "document". This allows custom syntaxes to be written for it which represent their arbitrary AST as the
document
, containing one or moreRoot
nodes which are the actual CSS from said document.For example, CSS in JS solutions would result in a
Document
representing the JS file, and one or moreRoot
representing the contained stylesheets.When combined with tailwind, this works like so:
Document { nodes: [Root, Root] }
at this point)Tailwind then executes code like this to replace the at-rules:
tailwindcss/src/lib/expandTailwindAtRules.js
Lines 206 to 209 in 490c9dc
This works because
layerNode.base.parent
is one of the childRoot
nodes. So by callingbefore
, we're prepending child nodes to theRoot
, not theDocument
(GOOD).However, we can then reach this:
tailwindcss/src/lib/expandTailwindAtRules.js
Lines 239 to 241 in 490c9dc
Which, as you see, will append explicitly to
root
: theDocument
in this case.This will result in an AST like so:
When a custom syntax then attempts to stringify the AST back to the original non-css document, this misplaced
Rule
will be thrown on the end... causing a syntax error in the output.Solution?
I don't know tailwind's source well enough to suggest a solution here. Possibly, if any
layerNodes.*
exists, use its parent as the root. If none exist, fall back to what it does now?Or is there maybe an existing way to explicitly mark where those rules should exist? wherever
layerNodes.variants
comes from. Can we simply put some at-rule like@tailwindvariants
?Until this is fixed, custom postcss syntaxes can't really work with "variant rules".
The text was updated successfully, but these errors were encountered: