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

Puma plugin dependencies are not required #458

Closed
indirect opened this issue Jan 19, 2025 · 7 comments · Fixed by #459
Closed

Puma plugin dependencies are not required #458

indirect opened this issue Jan 19, 2025 · 7 comments · Fixed by #459

Comments

@indirect
Copy link
Member

Is there a chance you would consider updating the plugin to function correctly when puma is run directly, without getting run via rails s?

The Puma plugin is fantastic, and I would like to use it everywhere I use Puma, including with puma-dev. Unfortunately, the plugin uses constants and methods that are defined by libraries it does not require, like Tailwindcss::Commands and Rails.root. When run via rails s it just happens to work because the Rails boot process is finished before Rails starts Puma.

It's easy to reproduce this issue, just choose any app with the Puma plugin and run bundle exec puma. You'll see a backtrace like this one:

❯ bundle exec puma
Puma starting in single mode...
* Puma version: 6.5.0 ("Sky's Version")
* Ruby version: ruby 3.4.1 (2024-12-25 revision 48d4efcb85) +PRISM [arm64-darwin24]
*  Min threads: 3
*  Max threads: 3
*  Environment: development
*          PID: 10335
.bundle/ruby/3.4.0/gems/tailwindcss-rails-3.2.0/lib/puma/plugin/tailwindcss.rb:14:in 'block in start': uninitialized constant Tailwindcss (NameError)

      IO.popen(Tailwindcss::Commands.watch_command, 'r+') do |io|
               ^^^^^^^^^^^
        from .bundle/ruby/3.4.0/gems/tailwindcss-rails-3.2.0/lib/puma/plugin/tailwindcss.rb:9:in 'Kernel#fork'
        from .bundle/ruby/3.4.0/gems/tailwindcss-rails-3.2.0/lib/puma/plugin/tailwindcss.rb:9:in 'start'

To demonstrate that the issue is the plugin running code that it has not required, you can stop Puma from crashing by requiring the Rails app before the plugin runs, by adding this line directly before the call to plugin :tailwindcss:

require_relative "application"
plugin :tailwindcss if ENV.fetch("RAILS_ENV", "development") == "development"

Anyway, if possible, I would love for the plugin to not crash Puma when Puma is run directly. Thanks!

@flavorjones
Copy link
Member

Yup, that's a use case I don't think we had thought of. I'll look into it.

flavorjones added a commit that referenced this issue Jan 19, 2025
that is, not in `rails server`.

Closes #458
@flavorjones
Copy link
Member

Proposed improvement at #459

@flavorjones
Copy link
Member

flavorjones commented Jan 19, 2025

Hmm. Note that even if we include require "tailwindcss/commands", that file uses Rails.root which also isn't loaded yet.

@indirect Is there a good reason not to just add require_relative "application" to your puma config if you want to run it standalone?

@flavorjones
Copy link
Member

I've loosened the dependency on Rails in the "commands.rb" file in #459, should be good.

@flavorjones
Copy link
Member

@indirect
Copy link
Member Author

Awesome, thanks for the quick response and quick turnaround!

@954681
Copy link

954681 commented Jan 21, 2025 via email

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 a pull request may close this issue.

3 participants