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

Add codemod for migrating @variants and @responsive directives #14748

Merged

Conversation

RobinMalfait
Copy link
Member

@RobinMalfait RobinMalfait commented Oct 22, 2024

This PR migrates the @variants and @responsive directives.

In Tailwind CSS v2, these were used to generate certain variants of responsive variants for the give classes. In Tailwind CSS v3, these still worked but were implemented as a no-op such that these directives don't end up in your final CSS.

In Tailwind CSS v4, these don't exist at all anymore, so we can safely get rid of them by replacing them with their contents.

Input:

@variants hover, focus {
  .foo {
    color: red;
  }
}

@responsive {
  .bar {
    color: blue;
  }
}

Output:

.foo {
  color: red;
}

.bar {
  color: blue;
}

@RobinMalfait RobinMalfait requested a review from a team as a code owner October 22, 2024 10:00
Copy link
Member Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

Join @RobinMalfait and the rest of your teammates on Graphite Graphite

@RobinMalfait RobinMalfait changed the title Add codemod for migrating @variants and @responsive Add codemod for migrating @variants and @responsive directives Oct 22, 2024
@RobinMalfait RobinMalfait force-pushed the robin/feat/migrate-variants-and-responsive-directives branch from 329126b to 14e1cac Compare October 22, 2024 10:05
Copy link
Member Author

The confusing part here is that if you use @variants hover

@variants hover {
  .foo {
    color: red;
  }
}

If you then use it in your html as:

<div class="hover:foo focus:foo foo">hello world</div>

Then the following CSS is being generated:

.foo {
  color: red;
}
.hover\:foo:hover {
  color: red;
}
.focus\:foo:focus {
  color: red;
}

Which means that the variants listed in @variants don't matter. But foo is treated as a utility. So maybe the better solution is to wrap this in @layer utilities and migrate it to an @utility instead 🤔

Copy link
Member

@RobinMalfait Ah, yeah, I think you're right we should migrate this to @utility to not break stuff. Fun that it doesn't matter which variants you used anymore but makes it easier for us at least 🙈

Copy link
Member Author

Haha yeah that is a bit confusing. In v2 we generated everything ahead-of-time, and later introduced the just-in-time in v3. So in v2 we needed that information to generate all the CSS.

@RobinMalfait RobinMalfait force-pushed the robin/feat/migrate-variants-and-responsive-directives branch from f677933 to a2d0425 Compare October 22, 2024 13:41
Copy link
Member

@philipp-spiess philipp-spiess left a comment

Choose a reason for hiding this comment

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

Need to add the migrateVariantsDirective rule to the defaults now 🙈 Let's add a full integration test to make sure it indeed works

@RobinMalfait RobinMalfait force-pushed the robin/feat/migrate-variants-and-responsive-directives branch from c0bf210 to 13a8a63 Compare October 22, 2024 15:02
@RobinMalfait
Copy link
Member Author

Should be good to go now

Copy link
Member

philipp-spiess commented Oct 22, 2024

Merge activity

  • Oct 22, 12:07 PM EDT: The merge label 'merge-queue' was detected. This PR will be added to the Graphite merge queue once it meets the requirements.
  • Oct 22, 12:08 PM EDT: A user added this pull request to the Graphite merge queue.
  • Oct 22, 12:15 PM EDT: A user merged this pull request with the Graphite merge queue.

…14748)

This PR migrates the `@variants` and `@responsive` directives.

In Tailwind CSS v2, these were used to generate certain variants of responsive variants for the give classes. In Tailwind CSS v3, these still worked but were implemented as a no-op such that these directives don't end up in your final CSS.

In Tailwind CSS v4, these don't exist at all anymore, so we can safely get rid of them by replacing them with their contents.

Input:
```css
@Variants hover, focus {
  .foo {
    color: red;
  }
}

@Responsive {
  .bar {
    color: blue;
  }
}
```

Output:
```css
.foo {
  color: red;
}

.bar {
  color: blue;
}
```
@philipp-spiess philipp-spiess force-pushed the robin/feat/migrate-variants-and-responsive-directives branch from 13a8a63 to 5bf2efb Compare October 22, 2024 16:10
@graphite-app graphite-app bot merged commit 5bf2efb into next Oct 22, 2024
2 checks passed
@graphite-app graphite-app bot deleted the robin/feat/migrate-variants-and-responsive-directives branch October 22, 2024 16: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.

3 participants