josefarias/hotwire_combobox

main app controllers/index.js overrode

paulhenri-l opened this issue ยท 6 comments

Hi @josefarias, thanks for this great gem :)

I am facing a slight issue when using it. After installing the gem in my app my own controllers/index.js file got overrode by the combobox one. I think some namespacing needs to be done in the hotwire_combobox gem to prevent this form happening.

For now I renamed my controllers/index.js file to controllers/load.js and imported it inside my application.js file and it works now.
Please tell me if I can be of any help or if it's a misconfiguration on my side.

Hey @paulhenri-l thanks for the report!

Can you share more details about your app's asset handling? For instance, what library are you using for the JS pipeline, how you've installed stimulus, and how your controllers are loaded? And anything else you think might be useful in reproducing this.

We have a system test in place to make sure apps can load their own stimulus controllers. But it's entirely possible we missed some asset pipeline configuration that breaks things. Finding what it is about your configuration that makes things not work would be the first step in making sure we support your setup.

Thanks!

I reproduced the bug in this repo : https://github.com/paulhenri-l/combobox-test it's barebones rails assets handling as far as I know.

We can see in the browser resources that the app's controllers/index.js has been overriden by the combobox one :

image

If I comment the combobox gem from the gemfile I get this :

image

I think the combobox files can be put inside their own directory to avoid this collision.
Although this would probably prevent you from automatically loading the hw_controller ?

In my production app the app's controllers/index.js file looks like this :

image

Ah i think i see what's wrong here.

The system test passing is a false positive. Stimulus controllers are properly included via importmaps, not via index.js, which is what I intended to test. In your test repo, you're able to use the hello controller. But, as you pointed out, index.js is overridden by the gem.

Should be a simple fix. Probably achieved by namespacing like you suggested. I'll work on this soon as time allows, as I'm short on availability in the short term. Hopefully today.

Thanks for a great catch, diagnosis, and reproduction ๐Ÿ™

Should be fixed in the next release (v0.1.33). You can point the gem to the main branch in the meantime. Please let me know if this didn't fix your problem!

Hey @josefarias thanks for the quick fix! I'll try it tomorrow and keep you updated

It fixed my issue ๐Ÿ‘ thanks