rails / mission_control-jobs

Dashboard and Active Job extensions to operate and troubleshoot background jobs
MIT License
611 stars 71 forks source link

Issue with javascript_importmap_tags "application-mcj" import-map/sprockets resolving [v0.3.3] #179

Closed iJackUA closed 1 week ago

iJackUA commented 1 month ago

After update 0.3.2 > 0.3.3 it started to fail when accessing UI pages (RAILS_ENV=development)

web     |   Rendered /usr/local/bundle/gems/mission_control-jobs-0.3.3views/mission_control/jobs/queues/index.html.erb within layouts/mission_control/jobs/application (Duration: 9.9ms | GC: 0.0ms)
web     |   Rendered layout /usr/local/bundle/gems/mission_control-jobs-0.3.3views/layouts/mission_control/jobs/application.html.erb (Duration: 341.7ms | GC: 101.9ms)
web     | Completed 500 Internal Server Error in 554ms (ActiveRecord: 11.8ms (8 queries, 0 cached) | GC: 133.5ms)
web     | 
web     | 
web     |   
web     | ActionView::Template::Error (Asset `controllers/application.js` was not declared to be precompiled in production.
web     | Declare links to your assets in `app/assets/config/manifest.js`.
web     | 
web     |   //= link controllers/application.js
web     | 
web     | and restart your server):
web     | 
web     | Causes:
web     | Sprockets::Rails::Helper::AssetNotPrecompiledError (Asset `controllers/application.js` was not declared to be precompiled in production.
web     | Declare links to your assets in `app/assets/config/manifest.js`.
web     | 
web     |   //= link controllers/application.js
web     | 
web     | and restart your server)
web     |      9:   <meta name="turbo-cache-control" content="no-cache">
web     |     10:   <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bulma@1.0.1/css/bulma.min.css">
web     |     11:   <%= stylesheet_link_tag "mission_control/jobs/application", "data-turbo-track": "reload" %>
web     |     12:   <%= javascript_importmap_tags "application-mcj" %>
web     |     13: </head>
web     |     14: <body>
web     |     15: 
web     |   

Rails app itself uses sprockets, so I suppose it is related to issue that caused 0.3.3 fix https://github.com/rails/mission_control-jobs/issues/169 my app is not api-only and had no issues with 0.3.2, but it failed to make assets:precompile in production env with 0.3.2

still need to try, but maybe https://github.com/rails/mission_control-jobs/pull/163 is in the right direction (as in current error message it suggests manifest.js from parent app, but not from the mission_control engine, maybe it mixes them while precompiling?)

declaring it in "parent app" manifest.js liek suggested //= link controllers/application.js does not help (and I believe it should not), not sure why application-mcj is being translated into controllers/application.js path.

iJackUA commented 4 weeks ago

This is connected issues https://github.com/rails/mission_control-jobs/issues/140

In our setup we are also useing esbuild to compile JS. And sprockets-rails to handle "assets:precompile". I see that importmap-rails are also in the Gemfile, but it is not being used by our app.

iJackUA commented 4 weeks ago

While I still believe there should be a real solution, like PRs mentioned above.

Solution for those who are trying to find a workaround and have the same pre-conditions like mine: 1) this solution assumes that you are using smth else, not importmaps in yout Rails app! and Importmap was just pregenerated by rails new and never used, but also not removed. 2) remove gem "importmap-rails" from Gemfile 3) remove config/importmap.rb file

now mission_control does not overlap own importmap with your app's default importmap and works as expected!

rosa commented 2 weeks ago

Hey @iJackUA, this should have been fixed by #163. Do you mind verifying if things look good for you?

rosa commented 1 week ago

Going to close this one as it should be fixed now by #163.