Clobber and precompile assets after every change in stimulus controller

Hi all,

I’m trying to get back into rails development and recently started a project that I initiated with importmaps for managing javascript libraries. However I can’t seem to pin certain libraries and decided to migrate to asset pipeline. Through trial and error I made it work (by comparing my project with new project that was initiated with jsbundling-rails), however I feel that I have misconfiguration issues.

Whenever I change the code in a stimulus controller I have to clobber and precompile assets, because the change is not picked up in the browser. What can be wrong here? I’m also using the hotwire-livereload gem, however the result is the same with or without having livereload enabled in application’s layout.

What command do you start the js precompilation with? Did you forget --watch as argument?

I have a /bin/dev server with following

web: unset PORT && env RUBY_DEBUG_OPEN=true bin/rails server
js: yarn build --watch
css: yarn build:css --watch

I can also see the logs when I save js, html or css file that rebuild is happening. However it seems that sha sums change and they don’t get loaded into the website.

How are you including the js build in your HTML? Are you using Turbo as well? Does a “hard refresh” fix the path in the HTML?

Can you elaborate on including js build in html? I’m using standard javascript_include_tag for application.js:

<%= javascript_include_tag "application", "data-turbo-track": "reload" %>

The hard refresh (trying it on Safari after Cmd+Option+E) does not help.

Yes, that was what I meant with including it in the HTML. Well, that’s all I could think of, difficult to debug without access to the project. Do you have the ability to test it on a different machine? Might be useful to see if it works there.

1 Like

Thank you for your suggestions. I don’t have another machine to try, however I’ll continue trying on different project and finding diffs in configs and initializers.

Could try: bundle exec rails tmp:cache:clear