-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Describe the bug
I use Hotwire Stimulus for JavaScript and recently included it in rails admin.
If I change any of the JavaScript files, I have to restart the server for the change to take effect in rails admin.
This is frustrating as a developer since I want to make a change and immediately see it.
I've got a workaround so it isn't an issue, but it took me a long time to understand the issue. It could just be me, in which case you can remove this issue
Reproduction steps
I still use Sprockets as well as Importmap, so had to amend one line to get Importmap to work, which is why I wonder if its me.
File lib\rails_admin\engine.rb
Duplicated original line 54 (importmap assignment) into when :sprockets block.
https://github.com/Cardyard/rails_admin/blob/master/lib/rails_admin/engine.rb#L55
Also in file app/views/layouts/rails_admin/_head.html.erb duplicated the Importmap block into :sprockets block.
https://github.com/Cardyard/rails_admin/blob/master/app/views/layouts/rails_admin/_head.html.erb#18
I'm sure this issue would also arise when simply choosing importmap as the asset delivery.
Now add a stimulus controller (in JavaScript) on a page in rails admin and view it. Make a change to that controller and refresh the page. Best case no change, worse case 404 error as the fingerprint has changed on the underlying file and can no longer be found. To see the change have to restart the server.
Expected behavior
Make changes to your hearts content and see the change on refresh in rails admin view.
Additional context
A fix is also implemented in the forked repository by having the following line in the layout file _head.html.erb..
<% RailsAdmin::Engine.importmap = Importmap::Map.new.draw(Rails.root.join('config/importmap.rails_admin.rb')) if Rails.env.development? %>
It would have been better if the system could have taken care of this itself by having an Importmap instance that contained a cache_sweeper and file watcher and refreshed the map when files changed. The Importmap solution in rails admin is brilliant, allowing a separation of JavaScript between the main app and admin, but it doesn't refresh the map when a file is altered.
We heavily customise rails admin by adding collections and member actions, so being able to quickly see a change is important.
Though must say, this rails admin is the best there's ever been, thanks for a great solution x