'Rails 7 - picking up assets automatically in dev doesn't work
For some unknown reason Rails 7 (development environment) doesn't pick up changes in application.js automatically when I hit F5 in the browser. The location application.js is default. I'm using pretty much default setup.
When I run the server, it picks up javascript from some cached version. I need to explicitly rails assets:recompile to make it work.
Importmap looks standard:
# Pin npm packages by running ./bin/importmap
pin "application", preload: true
...
And layout file seems pretty standard as well:
<!DOCTYPE html>
<html>
  <head>
    <title>Whatever</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="icon" href="<%= image_path('favicon.svg') %>">
    <%= csrf_meta_tags %>
    <%= csp_meta_tag %>
    <%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
    <%= javascript_importmap_tags %>
  </head>
...
I tried to set config.importmap.sweep_cache = true in my development.rb (as per importmap docs), but it seems there is no effect.
At this point I'm pretty desperate and can't understand why do I need to rails assets:precompile on my development environment.
Also, I'm not running my app on "localhost" domain, it's on something like dev.server-somewhere.com (so it's accessible from anywhere) with SSH redirects, similar to ngrok. Not sure if it's the cause of a problem.
For clarification: I'm looking for no LIVE refresh feature, just the standard approach with F5 page refresh would work.
Solution 1:[1]
I have same problem, simply use: rails assets:clobber to clear all precompiled assets. After that the hot reloading will start working again.
For some reasons even in Development mode if there are existing precompiled JS assets rails give them priority.
Solution 2:[2]
I have faced this issue today and I replaced the sprockets with the propshaft. Then it worked! You might look at the upgrade guide.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|---|
| Solution 1 | Tommaso Dri | 
| Solution 2 | Emrecan ?u?ter | 
