railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.88k stars 2.25k forks source link

Unable to precompile assets when updating to `3.0.0.beta` #3534

Closed codealchemy closed 2 years ago

codealchemy commented 2 years ago

Describe the bug

Attempting to run bundle exec rake assets:precompile raises an exception

Reproduction steps

Update gem in a project using :sprockets, attempt to precompile

Expected behavior

Assets to be compiled as before

Additional context

(reduced this down to the essential bit of the error as we have internal middlewares in addition to those from Rails)

FrozenError:
  can't modify frozen Array: [... middleware classes ]
/project_dir/vendor/bundle/ruby/2.7.0/gems/actionpack-6.0.5/lib/action_dispatch/middleware/stack.rb:126:in `push'
/project_dir/vendor/bundle/ruby/2.7.0/gems/actionpack-6.0.5/lib/action_dispatch/middleware/stack.rb:126:in `use'
/project_dir/vendor/bundle/ruby/2.7.0/gems/<internal gem>:in `block in <class:Engine>'
/project_dir/vendor/bundle/ruby/2.7.0/gems/railties-6.0.5/lib/rails/initializable.rb:32:in `instance_exec'
/project_dir/vendor/bundle/ruby/2.7.0/gems/railties-6.0.5/lib/rails/initializable.rb:32:in `run'
/project_dir/vendor/bundle/ruby/2.7.0/gems/railties-6.0.5/lib/rails/initializable.rb:61:in `block in run_initializers'
/project_dir/vendor/bundle/ruby/2.7.0/gems/railties-6.0.5/lib/rails/initializable.rb:60:in `run_initializers'
/project_dir/vendor/bundle/ruby/2.7.0/gems/railties-6.0.5/lib/rails/application.rb:363:in `initialize!'

This appears to be related to changes to initialization from https://github.com/railsadminteam/rails_admin/commit/e59a9353e742b0f6e6b152d1b1f9e7cafad3ee54

Workaround

Keep only the precompile initializer during precompilation

# application.rb

if ENV.fetch('PRECOMPILE', false)
  RailsAdmin::Engine.initializers.keep_if { |i| i.name == 'RailsAdmin precompile hook' }
end
codealchemy commented 2 years ago

I was able to narrow this down to the RailsAdmin apply configuration initializer - my issue looks to be similar to https://github.com/railsadminteam/rails_admin/issues/3533 where the change from https://github.com/railsadminteam/rails_admin/commit/e59a9353e742b0f6e6b152d1b1f9e7cafad3ee54 causes issues with other engines that affect application middleware. Closing to consolidate under #3533