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

Default config should not watch log directory (and probably others) #491

Closed
alexandergitter opened this issue Feb 6, 2025 · 9 comments
Closed

Comments

@alexandergitter
Copy link

I noticed that on a new Rails app, Tailwind seems to be running quite frequently during HTTP requests, even if no files have changed. It appears that Tailwind watches the log files, where new log lines get appended frequently.

To reproduce this I'm doing the following:

  • create a new Rails app via rails new MyApp --css tailwind
  • run it with bin/dev
  • change something in a log file, e.g. echo "foo" >> log/development.log
  • observe that tailwind outputs something like 17:01:26 css.1 | Done in 3ms

It would be nice if the default generated configuration excludes the log directory and probably others like tmp and storage.

OS: Ubuntu 24.04
Ruby: 3.3.6
Rails: 8.0.1
tailwindcss-rails: 4.0.0
tailwindcss-ruby: 4.0.4

@flavorjones
Copy link
Member

@alexandergitter Thanks for opening this issue, sorry you're experiencing that.

I can't reproduce what you're seeing, though! Tailwind v4 has some heuristics for what files it chooses to scan:

https://tailwindcss.com/blog/tailwindcss-v4#automatic-content-detection

Notably I'll quote from that section:

For example, we automatically ignore anything in your .gitignore file

By default Rails include /tmp/* and /log/* in the generated .gitignore, so I think that's why I can't reproduce this in my environment. Have you modified your ignores?

Any additional information you can provide me so that I can reproduce what you're seeing would be valuable

@patriciomacadden
Copy link
Contributor

I think this is a configuration issue. v4 dropped the configuration file (tailwind.config.js) in favor of css directives. By default, tailwind will scan everything under the cwd. See detecting classes in source files.

Indeed, if I echo "foo" >> log/development.log it will re-build the css file.

But you can fix that by doing:

@import "tailwindcss" source("../../");

See registering sources.

this will only watch the app directory.

@flavorjones
Copy link
Member

@patriciomacadden I think we posted at the same time. Please see my comment above about how the v4 cli chooses to ignore files, it does not scan everything.

@flavorjones
Copy link
Member

🤔 Ok, I think I know what's going on here. When you echo something into "log/development.log" you see a line from the tailwindcss process Done in 624µs or similar. OK.

But the CSS files are not being regenerated when this happens. You can demonstrate this by deleting app/assets/build/tailwind.css and echoing into the log file. It does not get regenerated.

I think the "Done in Xms" message is saying that a file changed on disk, not that the CSS file has been regenerated.

In any case, this gem doesn't have control over what the upstream tailwindcss CLI executable emits, unfortunately. You may want to open an issue upstream?

Closing because I don't think there's a specific config change I can (or should) make here.

@flavorjones
Copy link
Member

@patriciomacadden If you think changing the config to @import "tailwindcss" source("../../"); is the right thing to do, open a PR and we can talk about it?

I'm not at all sure that limiting tailwind to the app directory is going to necessarily be the right thing, though. Specifically I'm thinking about helper methods in lib, etc.

@flavorjones flavorjones closed this as not planned Won't fix, can't repro, duplicate, stale Feb 6, 2025
@flavorjones
Copy link
Member

Ah, hmm, this looks like it's a bug in upstream in any case: tailwindlabs/tailwindcss#15684

@patriciomacadden
Copy link
Contributor

I don't think it's necessary right now. It's not building the css and it's not spending a lot of time doing what it does. Even though we could add other directories using @source, it could make things harder debug, for example.

All good for me.

@alexandergitter
Copy link
Author

Thank you both, I'll keep an eye on the upstream issue.

@ur5us
Copy link

ur5us commented Mar 5, 2025

I’d like to point out that while Tailwind v4 might not change the generated output and is rather quick in doing so, this behavior is still an issue overall because it causes a lot of CPU load. In my case, I use GoodJob with a bunch of scheduled (cron/periodic) tasks. As GoodJob logs to log/development.log and this is picked up by Tailwind, this causes said high CPU load. Having said, I agree that this is an upstream issue.

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

No branches or pull requests

4 participants