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

supports variant compiles function syntax incorrectly #13594

Open
adamwathan opened this issue Apr 26, 2024 · 5 comments · Fixed by #13596
Open

supports variant compiles function syntax incorrectly #13594

adamwathan opened this issue Apr 26, 2024 · 5 comments · Fixed by #13596

Comments

@adamwathan
Copy link
Member

What version of Tailwind CSS are you using?

v3 and v4

Reproduction URL

https://play.tailwindcss.com/ySYgzSn5FT

Describe your issue

Classes like supports-[font-format(opentype)]:grid generate invalid CSS, because we currently assume that supports values that don't contain : are a CSS property and we insert a variable at the end in an attempt to make the query valid:

@supports (font-format(opentype): var(--tw)) {
  .supports-\[font-format\(opentype\)\]\:grid {
    display: grid;
  }
}

This isn't a crazy complicated thing to fix but there are a number of test cases to consider:

supports-[font-format(opentype)]:grid
supports-[content:"("]:grid
supports-[(display:grid)_and_font-format(opentype)]:grid
@brandonmcconnell
Copy link
Contributor

brandonmcconnell commented Apr 26, 2024

One solution here could be to explicitly detect and ignore known function syntaxes, as it appears to be a very finite and set concrete list:

  • font-format()
  • font-tech()
  • selector()

Doing it this way and not arbitrarily matching a string(…) pattern would also avoid matching for all strings where some others are valid non-function syntax (e.g. and|or|not).


UPDATE: In my related PR #13596, I opted to support the hyphen character in supports checks, which appears to fix the issue and resolve the cases you mentioned with one exception (details below) and add support for custom properties the same way we currently support native ones.

  • supports-[display]@supports (display: var(--tw))
  • supports-[--test]@supports (--test: var(--tw))

@brandonmcconnell
Copy link
Contributor

Thoughts for the future — it could be helpful to set up extensions to the supports rule to support each of the function syntaxes in the future, e.g.:

  • supports-font-format-[opentype]
  • supports-font-selector-[h2>p]

⚠️ This still wouldn't account for the present use case of using them inline, which is the immediate need

@brandonmcconnell
Copy link
Contributor

@adamwathan I opened PR #13596, which should resolve this issue. It does not fix the supports-[content:"("]:grid test you mentioned, but as that does not appear to be directly related to the supports-variant effort and is more related to the parser itself, I would prefer to handle that case in a separate PR.

You can see here that this was an issue before: https://play.tailwindcss.com/M7FOiImx9l

I confirmed that example (supports-[content:"("]:grid) doesn't reach the test, so it would appear to be filtered out by the parser. supports-[content:"test"]:grid works, indicating that the parenthesis is the other example is problematic. I'll take a deeper look at how the parser handles quoted strings inside arbitrary values and see if something is missing there.

@adamwathan
Copy link
Member Author

Reopening so we fix this in v3 as well.

@brandonmcconnell
Copy link
Contributor

@adamwathan #13605 should fix this for v3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants