Hotwire Discussion

Accumulating stimulus controllers from multiple engines?

Earlier this year I was asked to look into a modular contribution model for a project. Engines are great for putting a boundary around things, and another team has been building out their own models and views using a library of view components I created, that uses stimulus to provide some runtime behaviours.

Now the contributing team want to build their own stimulus controllers to enable/disable aspects of their forms, and some other complex behaviours.

The view-components engine already defined a layout with its javascript import map shims in the page head, so new controllers defined in an engine are not picked up.

I think I need to have the “main” application collect controllers from multiple engines then inject/build those into the main layout somehow. I will look into this tomorrow, but wondered if anyone has any information/code/patterns for doing this?