404 on assets/stimulus-loading.js with config.assets.digest set to false
mrkcor opened this issue ยท 11 comments
When turning the asset digests off (https://guides.rubyonrails.org/asset_pipeline.html#turning-digests-off) in the development environment by setting config.assets.digest
to false
in config/environments/development.rb
the file assets/stimulus-loading.js
will not load and you will get an HTTP 404 for that file:
Changing config/importmap.rb
to pin to stimulus-loading
instead of stimulus-loading.js
will make it work in the environments where the asset digests are turned off, the file will then however not be included in the production assets when precompiling them.
I have created a new Rails app where you can reproduce this issue here: https://github.com/mrkcor/stimulus-loading-issue
For anyone looking for a workaround for this issue: you can put a copy of the file stimulus-loading.js
in vendor/javascript
and pin the file as is indicated in the README.
Hi @mrkcor, I just came to this repo to report the same bug. Thank you for the workarounds!
You're welcome @tripptuttle ๐
Possibly related to rails/sprockets#749
Unable to reproduce on latest Rails and latest dependencies against a new stock app.
@dhh this is easily reproducible with the latest stable Rails release (7.0.7):
% rails new assets-test && cd assets-test
% echo "Rails.application.config.assets.digest = false" >> config/initializers/assets.rb
% bin/rails s &
% curl http://localhost:3000/assets/stimulus-loading.js
I had missed this was a specific issue with turning off assets digest. Why are folks doing that? Keeping those digests in development is the preferred approach. But I'll reopen anyway.
@dhh personally I never do it, but I was having some trouble with assets recompilation in development, and one of the suggested solutions was to set this in config/development.rb
:
config.assets.compile = true
config.assets.digest = false
This is how I stumbled upon this issue.
I was turning it off because of this issue with livereload: guard/guard-livereload#169 (comment)
I had missed this was a specific issue with turning off assets digest. Why are folks doing that? Keeping those digests in development is the preferred approach. But I'll reopen anyway.
@dhh, I also got bitten by this when used together with guard/guard-livereload#169 (comment). Live reloading is wonderful together with Tailwind, makes designing directly in the browser so quick that I've stopped using Figma. However, setting up live reloading in Rails is usually a hassle. Have used chokidar with node earlier, and now using guard + rack-livereload. Neither option is as simple as it should be. Would be great to have a canonical and easy way to get it working on a new rails app without lot's of tricky dependencies.