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:precompile
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.
I have same problem, simply use: rails assets:clobber
to clear all precompiled assets. After that the hot reloading will start working again.
if existing precompiled JS assets exist in public/assets/
rails gives them a priority even in development mode (and even when, for example, esbuild or tsc-watch is otherwise working to transpile your source files into app/assets/buils/
, which is unrelated to Sprocket hanging onto its old cache)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With