Fix Madmin importmap assets with Propshaft - #343
Conversation
|
I haven't seen this and I use propshaft. Create a new Rails application to that reproduces the issue so we can see what exactly causes it if there is a load order issue somewhere. And please share the exact error(s) you were seeing. Also Madmin works with sprockets, so we can't merge a change like this. If you want to run the tests against sprockets, use the appraisal: |
|
@excid3 Here’s what I did locally to run the app. From the repo root: bundle install
bundle exec bin/rails db:create
bundle exec bin/rails server -p 3000Then I opened the app. The page rendered, but none of the local JavaScript loaded, and the browser console showed 404s for the asset URLs generated by the page:
So /madmin itself returned 200 and rendered HTML, but the importmap/local asset URLs in that page were unresolved, which left the admin UI without working JS. Sorry, maybe I'm doing something wrong, and that's why it's not working 🙏 |
|
I just pushed a couple small clean up things. I confirmed it works fine with both propshaft and sprockets in our test suite dummy app. You can clone the repo, bundle, and run Your Gemfile needs to require either one so that source "https://rubygems.org"
gem "rails", "~> 8.1.3"
gem "propshaft" |
I hope this wasn't just an issue on my machine, but I ran into broken local asset URLs in the dummy app and traced it back to Propshaft not being loaded before the engine booted.
Summary
propshaftbefore booting the engine so importmap asset paths resolve correctly/madminProblem
The dummy app rendered importmap tags, but local asset URLs were unresolved and fell back to broken paths like:
/madmin/application.js/turbo.min.js/stylesheets/dummy.cssThat left Madmin with missing JavaScript and CSS in development.
Fix
Load
propshaftbeforemadmin/engineso the asset server is available when importmap and stylesheet helpers resolve Madmin assets.