rails / mission_control-jobs

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

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

Open searls opened 3 weeks ago

searls commented 3 weeks 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 3 weeks 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