ai / autoprefixer-rails

Autoprefixer for Ruby and Ruby on Rails
https://twitter.com/autoprefixer
MIT License
1.22k stars 109 forks source link

autoprefixer sometimes does not activate on Rails 7 #215

Closed zarqman closed 2 years ago

zarqman commented 3 years ago

On a new Rails 7.0.0.alpha2 app, it seems that autoprefixer-rails no longer activates if it appears before sprockets-rails in the Gemfile.

# gem 'autoprefixer-rails' # when above, silently fails to activate
gem 'sprockets-rails'
gem 'autoprefixer-rails'   # when below, activates properly

So far I've confirmed that in railtie.rb, app.assets is nil not only during the original require, but also when the :setup_autoprefixer initializer is actually executed, which is why it fails to activate.

As to why app.assets is nil at that stage, I'm not completely sure, but it might be because sprockets-rails is now optional in Rails 7 and is itself initializing later in the boot process.

Hoping this provides a workaround for anyone else encountering the same issue and also provides a headstart on resolving it.

Edit: see fix in PR #216