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

Template migrations: Add automatic var injection codemods #14526

Merged
merged 17 commits into from
Oct 1, 2024

Conversation

philipp-spiess
Copy link
Member

In v4, we're removing automatic var injection (please refer to this PR for more detail as to why).

Automatic var injection made it so that if you have a candidate like bg-[--my-color], v3 would automatically wrap the content of the arbitrary section with a var(…), resulting in the same as typing bg-[var(--my-color)].

This PR adds codemods that go over various arbitrary fields and does the var(…) injection for you. To be precise, we will add var(…) to:

  • Modifiers, e.g.: bg-red-500/[var(--my-opacity)]
  • Variants, e.g.: supports-[var(--test)]:flex
  • Arbitrary candidates, e.g.: [color:var(--my-color)]
  • Arbitrary values for functional candidates, e.g.: bg-[var(--my-color)]

@philipp-spiess philipp-spiess force-pushed the feat/automatic-var-injection-codemod branch from f040289 to b378d29 Compare September 26, 2024 15:28
@philipp-spiess philipp-spiess marked this pull request as ready for review September 26, 2024 15:28
@adamwathan
Copy link
Member

In v3, some utilities didn’t automatically wrap things in var() (there’s a list in the codebase somewhere), so we should make sure not to mod those ones here 👍🏻

Comment on lines 34 to 35
['supports-[--test]:flex', 'supports-[var(--test)]:flex'],
['supports-[_--test]:flex', null],
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if these are correct, because
supports-[--test] maps to @supports (--test: var(--tw)) which essentially tests whether the browser understands CSS variables.

But supports-[var(--test)] maps to @supports var(--test) which I think is invalid? (at least I can't get it to work in Safari with any value I throw at it)

https://play.tailwindcss.com/CC7NDpsJfg

Copy link
Member Author

Choose a reason for hiding this comment

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

Ah, I got this from your list here: https://github.com/tailwindlabs/tailwindcss/pull/13657/files#diff-5c09a7c68a4426650ba1209e3be9652052750e24131acb607e09e5efea477dacR1619-R1624

supports-[var(--test)] mapping to @supports var(--test) seems to be at least compatible with v3 though 🙈

Screenshot 2024-09-26 at 18 19 27

Copy link
Member

@RobinMalfait RobinMalfait Sep 27, 2024

Choose a reason for hiding this comment

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

Hmm I see. While this is compatible with v3, it's still wrong (aka will never match). So the question is:

  1. Do we want to fix it (could be a breaking change since it's already broken right now)
  2. Do we get rid of the supports variant in this case (or the candidate entirely because it won't do anything anyway)
  3. Do we do what v4 expects, where it maps to --test: var(--tw) (which essentially is the fix from 1.)
  4. Don't do anything

Copy link
Member

@RobinMalfait RobinMalfait left a comment

Choose a reason for hiding this comment

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

Looking nice! Just a few suggestions

@philipp-spiess philipp-spiess merged commit c0dd000 into next Oct 1, 2024
3 checks passed
@philipp-spiess philipp-spiess deleted the feat/automatic-var-injection-codemod branch October 1, 2024 11:23
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.

3 participants