propshaft: change is not detected in @import css file
If I understood correctly the idea of Portshaft (pls correct me if I’m wrong ) then the way how to include css files would be:
in app/assets/application.css
/* Application styles */
@import url('/bootstrap.css');
@import url('/my-custom.css');
in app/assets/bootstrap.css I have the content of bootstrap.css from Bootstrap 5 download page
in app/assets/my-custom.css:
p {
color: red;
}
my app/views/layout/application.css
<!DOCTYPE html>
<html>
<head>
<title>Myapp</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<%= csrf_meta_tags %>
<%= csp_meta_tag %>
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
<%= javascript_importmap_tags %>
</head>
<body>
<h1>Propshaft test</h1>
<div class="text-primary">
If this text is blue, Bootstrap5 css works via Portshaft
</div>
<p>If this text is in color then @include css custom file works</p>
</body>
</html>
So far so good, I run rails server and load the localhost:3000
you can see the <p> is in red
Now I change the app/assets/my-custom.css:
p {
color: yellow;
}
I save the file and reload my localhost:3000
As you can see the change that I want the collor of <p> to be yellot was not picked up.
Restarting of rails server don’t help, only thing that helps is if I rename the file e.g. from app/assets/my-custom.css to app/assets/my-custom-xx.cssand alter the app/assets/application.css`
/* Application styles */
@import url('/bootstrap.css');
@import url('/my-custom-xx.css');
now it the
is yellow
- this is fresh Rails 7.0.2.4 & Ruby 3.1.1 project generated with
rails new myapp -a propshaft - no I didn’t run
rails assets:precompile
rails assets:reveal
bootstrap.css
application.css
my-custom-xx.css
my-custom.css
stimulus.min.js
stimulus.js
stimulus.min.js.map
stimulus-importmap-autoloader.js
stimulus-autoloader.js
stimulus-loading.js
turbo.min.js.map
turbo.js
turbo.min.js
es-module-shims.js.map
es-module-shims.js
es-module-shims.min.js
actiontext.js
trix.js
trix.css
action_cable.js
actioncable.esm.js
actioncable.js
activestorage.esm.js
activestorage.js
rails-ujs.js
application.js
controllers/hello_controller.js
controllers/index.js
controllers/application.js
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 1
- Comments: 22 (6 by maintainers)
Fixed by https://github.com/rails/propshaft/pull/188
We need to fix the underlying issue. Just saying it’s not a problem for us because we don’t use includes. But you should be able to use includes. Propshaft needs to build a transient dependency tree like we do we with template caching.
Hey @brenogazzola and @equivalent, I’m reading this issue and the PRs with the solution attempts.
I wonder if when in DEV ENV, refreshing the digest for
application.csson every request could solve the issue 🤔application.cssevery time it compiles the assetsBTW when I say
application.cssit should consider all the files set in the load path.What do you think?
Directly including the CSS via
stylesheet_link_tagcan avoid the@importproblem, but it still can leave you with stale assets such as background images. Changing the image data won’t cause the CSS digest to update, so clients will hold onto the old CSS and image. If the browser dumps the image out of its cache but not the CSS, the user would potentially even get a broken link.@equivalent Yeah, thanks - a
stylesheet_link_tagper file solves this indeed. The:alloption isn’t viable in my case, because order matters. A little uglier than@includeinapplication.css, but I can live with this 😊Sorry for the lack of feedback, things are a big rushed for me lately. I’ll try to take a look next week. 🙇♂️
…and I’ve just tested that by “Disable cache (while DevTools is open)” I’ve also solved the original issue with
@importso no PR that would track File.mtime neededBut it would be nice to point this out in advance in the README.md (it’s a new gem, will be hard to spot this for a newcomers like me ) I’ve created -> https://github.com/rails/propshaft/pull/94
To sum it all up:
This is not an issue:
BUT if are in development ENV doing lot of changes your browser by default caches everything, you will notice simmilar issues. Solution =>
Disable cache (while DevTools is open)ok to close this Issue from my side
Same me for my projects. I’ve manually specified individual
stylesheet_link_tag "css1", `stylesheet_link_tag “css2”, … (thx to http2 not an issue to have them many) and all ok. As long as one is aware of this issue it’s easy to avoid it.@pch
We use
stylesheet_link_tag :allin ONCE/Campfire.