Stimulus controller not working in lazy loaded frame

I’ve noticed that if I lazy-load a turbo-frame that uses a stimulus controller that isn’t used in the containing page, then the controller isn’t loaded (no connect method called) when the frame is introduced to the DOM. I’ve managed to work around it for now by just putting something like
<span data-controller="treeview"></span>
in the containing page to make sure that the controller is loaded.

Is there a better way to do this?

1 Like

I believe this is a bug and will be fixed in upcoming releases


This has been fixed in latest stimulus-rails that uses a new autoloader based on the mutation observer.