I have 2-3 existing Stimulus controller (created previously). These load fine.
Today I created a couple new Stimulus controllers. These are not being linked in <head> and, thus, not loading at all.
In the server log I get this:
Importmap skipped missing path: controllers/full_screen_controller.js
Importmap skipped missing path: controllers/element_closer_controller.js
Importmap skipped missing path: controllers/share_controller.js
Importmap skipped missing path: controllers/xxx_controller.js
That explains why these are not showing up in <head>. But it’s still not clear why these specifically are “missing”.
I think I have narrowed this down to a problem with import maps (and possibly some interaction with the content_security_policy).
I suspect this may have something to do with the content_security_policy in config/initializers/content_security_policy.rb where these are set:
config.content_security_policy_nonce_generator = ->(request) { request.session.id.to_s }
config.content_security_policy_nonce_directives = %w(script-src style-src)
But what’s odd is that even when I completely turn off the CSP, it still doesn’t work.
I’m trying to walk through the importmap-rails code starting with javascript_importmap_tags (and trying to find my way down to resolve_asset_path where the warning appears to come from.)
The method javascript_importmap_tags starts with Rails.application.importmap which, when I look in the console, does have all of the Stimulus controllers.
But the new Stimulus controllers are not in the importmap or <head> <link>s by the time everything is fully generated.
Has anyone else run into this?
Is there a cache I’m not aware of?