10000 Migrate to tailwind v4 by mgrunberg · Pull Request #8640 · activeadmin/activeadmin · GitHub
[go: up one dir, main page]

Skip to content

Migrate to tailwind v4 #8640

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

Closed
wants to merge 14 commits into from
Closed

Migrate to tailwind v4 #8640

wants to merge 14 commits into from

Conversation

mgrunberg
Copy link
Contributor
@mgrunberg mgrunberg commented Feb 26, 2025

This PR migrates Tailwind v3 to v4. In the process, it upgrades flowbite from 2.3.1 to 3.1.2 (latest).

I made the minimum changes to support v4. I don't pretend to support v3.

Note: I didn't check that the app looks as good as before. Based on @javierjulio comments, that shouldn't be a problem.

Breaking changes

  • Configuration file now has .mjs extensions. That removes a warning if your project (package.json) is not a type module.

Next steps

The goal of this PR is just to use Tailwind v4. I will try to remove js configuration file and plugin usage in another PR

@tagliala
Copy link
Contributor

Thanks, during the process, can you please check if #8574 will be fixed or if we need to merge that?

@mgrunberg
Copy link
Contributor Author

Sure! Thanks for the reminder. Are you aware of other issue / topic like that?

@javierjulio
Copy link
Member

I will take care of #8574 since I need to address other related styles that aren't complete. I will get to it. Please be patient.

Copy link
codecov bot commented Feb 26, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.11%. Comparing base (542f7d6) to head (92413c5).
Report is 19 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #8640   +/-   ##
=======================================
  Coverage   99.11%   99.11%           
=======================================
  Files         141      141           
  Lines        4073     4073           
=======================================
  Hits         4037     4037           
  Misses         36       36           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mgrunberg mgrunberg marked this pull request as ready for review February 26, 2025 22:26
@mgrunberg mgrunberg requested review from javierjulio and tagliala and removed request for javierjulio February 26, 2025 22:27
Copy link
Member
@javierjulio javierjulio left a comment

Choose a reason for hiding this comment

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

Looks like the renamed utilities didn't affect us much so that's great. I didn't realize Flowbite had a v3 update. I'll try to look into the plugin changes and see what we need to bring in. Thank you.

@@ -8,7 +8,7 @@ def install_assets
remove_file "app/assets/stylesheets/active_admin.scss"
remove_file "app/assets/javascripts/active_admin.js"
template "active_admin.css", "app/assets/stylesheets/active_admin.css"
template "tailwind.config.js", "tailwind-active_admin.config.js"
template "tailwind.config.js", "tailwind-active_admin.config.mjs"
Copy link
Member

Choose a reason for hiding this comment

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

I'm hesitant to do this. What did you run into that you had to make this change? Wouldn't the original version just be treated as an ESM file by the host app as expected? Was there a warning or error by loading this in the new approach from the CSS file now?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted the change. I'm getting a console warning when I compile the CSS using node 20.x. It's safe to trust that apps are type module nowadays (or wait for issues)

image

Copy link
Member
@javierjulio javierjulio Mar 1, 2025

Choose a reason for hiding this comment

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

Thanks! Hmm that's strange because we do set it in our package.json file.

"type": "module",

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's our package.json, the problem is the test_app. I can't point out who generates that package.json. It could be jsbundling-rails

@mgrunberg
Copy link
Contributor Author

Looks like the renamed utilities didn't affect us much so that's great.

You are right, it was a nice surprise.

I didn't realize Flowbite had a v3 update.

It's relatively new (2025-01-24). @tagliala chose the perfect time to start the conversation about this migration 😄.

I'll try to look into the plugin changes and see what we need to bring in. Thank you.

Thanks for taking a look into the plugin changes.

Please consider that Tailwind V4 made changes to its preflight.

@tagliala
EDBE Copy link
Contributor
tagliala commented Mar 1, 2025

It's relatively new (2025-01-24). @tagliala chose the perfect time to start the conversation about this migration 😄.

That was intentional, I did wait for flowbite and css-bundling (which we are using on the CI) support for v4 before, I wouldn't have asked otherwise

I'm experimenting with flowbite 3 + tailwind 4 here: https://github.com/diowa/ruby3-rails8-flowbite-render

@tailwind utilities;
@import "tailwindcss";

@config "../../../tailwind-active_admin.config.js";
Copy link
Contributor

Choose a reason for hiding this comment

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

The javascript config file is needed by flowbite?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, the config file is needed to instruct Tailwind to scan our view files (active-admin distributed views).

There is no standard replacement for https://github.com/activeadmin/activeadmin/blob/master/lib/generators/active_admin/assets/templates/tailwind.config.js#L10 yet.

tailwindcss-rails has an ongoing discussion about engine support here.

I'm playing around with an idea on how to use CSS configuration in 34227e3

@velles
Copy link
velles commented Mar 7, 2025

@mgrunberg thank you for doing this upgrade. I needed it in order to use vite_rails in my project.
I just wanted to let you know that once tailwindcss is updated to v4 (which I manually patched in my project using some of your work), vite_rails can be easily integrated with the default setup.

So your upgrade will make part of ActiveAdmin vite_rails installation straightforward using default vite_rails setup and the tailwindcss for vite setup below.

import { defineConfig } from 'vite'
import tailwindcss from '@tailwindcss/vite'
import ViteRails from 'vite-plugin-rails'

export default defineConfig({
  plugins: [
    tailwindcss(),  
    ViteRails(),
  ],  
})

I can make a PR to update the docs once your PR merges.

@tagliala
Copy link
Contributor
tagliala commented May 5, 2025

Superseded by #8709

@tagliala tagliala closed this May 5, 2025
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.

4 participants
0