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
Allow app to opt out of precompiling activestorage js assets #43967
Conversation
@dhh I am taking the liberty of pinging you, as you're the one who introduced those new assets (and also the one who added the optout option for Action Cable ones). And @rafaelfranca because you were tagged in 3fd4185 (which is basically the same as this PR) so I guess you may be interested by this one |
It looks good. Could you rebase? |
54a6305
to
8763cff
Compare
Done ✔️ |
Sorry, could you also squash to a single commit? (https://edgeguides.rubyonrails.org/contributing_to_ruby_on_rails.html#squashing-commits) |
8763cff
to
19a7037
Compare
Done ✔️ |
19a7037
to
dd4f635
Compare
@ghiculescu is there anything missing to approve this PR ? |
It just needs review from the core team :) |
Ok thanks for your answer. No need to add them as reviewers ? For people who would look for a temporary fix, here's what we added in our initializer "active_storage.remove_assets", after: "active_storage.asset" do |app|
app.config.assets.precompile -= %w[activestorage activestorage.esm]
end |
Rails.application.config.assets.precompile += %w( activestorage activestorage.esm ) | ||
config.after_initialize do |app| | ||
if Rails.application.config.respond_to?(:assets) && app.config.active_storage.precompile_assets | ||
Rails.application.config.assets.precompile += %w( activestorage activestorage.esm ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't we just refer to app.config
here, rather than the two Rails.application.config
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
✔️ right, that's done.
I wrote it like this to be consistent with what you did in 3fd4185 but it's better like that. For consistency again, I changed the code in Action Cable too.
dd4f635
to
1a46c4a
Compare
Looking good. I know it's a little awkward with tests for this. So just want to confirm that you've verified this working in your local app? |
Yes, I tested it locally using gem 'rails', '~> 7.0', github: 'wecasa/rails', branch: 'activestorage_assets_precompile_optout' in my Gemfile. And I could be able to use this new |
Summary
Since PR #42895, Active Storage adds 2 JS assets to precompile:
rails/activestorage/lib/active_storage/engine.rb
Lines 169 to 173 in a8d088f
It's currently not possible to opt out. Our app does not use this Active Storage JS and it causes some issues with Sprockets and Uglifier. It would be helpful if we could disable this assets addition in the config.
Other Information
Action Cable has the same behavior of adding assets to precompile (introduced in #42856), but as you can see below it can be disabled:
rails/actioncable/lib/action_cable/engine.rb
Lines 26 to 32 in a8d088f
Specifically, this opt-out option was introduced by DHH in 3fd4185 so basically I mimicked this commit.