rails / mission_control-jobs

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

Does Mission Control's JavaScript need to be preloaded? [importmaps] #132

Closed searls closed 3 weeks ago

searls commented 5 months ago

Currently, I'm seeing this warning in my browser console everywhere in my app, even though mission control is only available on one authenticated route:

The resource /assets/mission_control/jobs/application-8d538c5b.js was preloaded using link preload but not used within a few seconds from the window's load event. Please make sure it wasn't preloaded for nothing.

This is because the gem's importmap.rb has every dependency set to preload: true, as in:

pin "application-mcj", to: "mission_control/jobs/application.js", preload: true

And (I think?) because the engine appends all these paths to the application's importmap config:

      initializer "mission_control-jobs.importmap", before: "importmap" do |app|
        app.config.importmap.paths << root.join("config/importmap.rb")
        app.config.importmap.cache_sweepers << root.join("app/javascript")
      end

Having every user, whether or not they are authorized to see the mission control jobs preload all of its JavaScript seems less than optimal. Is there any way around this?

searls commented 5 months ago

One workaround for end users is to mask the pin name and explicitly set preload to false in their own importmap.rb. It seems to work in that it clears the warning but doesn't break the functionality of /jobs

pin "application-mcj", to: "mission_control/jobs/application.js", preload: false
miharekar commented 2 months ago

Not entirely sure why these files even need to be a part of my application layout in the first place 🤔

The vast majority of users of most apps wouldn't have access to Mission Control, right?

henrikbjorn commented 2 months ago

Not entirely sure why these files even need to be a part of my application layout in the first place 🤔

The vast majority of users of most apps wouldn't have access to Mission Control, right?

See #163

rosa commented 3 weeks ago

This one should be fixed now thanks to @henrikbjorn 🙇‍♀️