-
Notifications
You must be signed in to change notification settings - Fork 791
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
sass load order problem after upgrading to 4.0.0.beta8 #597
Comments
We got stuck on the same problem. Did you manage to get a solution @jcoyne? |
No. |
I found I had to modify FYI, it turns out In case it helps, here's my complete manifest.js:
I'm using webpacker for JS, so it's not part of my Sprockets config. You might still need a line for such (although there too, you might want just Hint: Sprockets is overly generous when identifying directives and has a bad habit of ignoring what you think might be a commented out directive. If in doubt, delete old lines entirely. |
In sprockets 4.0.0, the `link_directory ../stylesheets .css` directive causes sprockets to process all `.scss` files in an arbitrary order, regardless of any `@import` statements. This leads to undefined variable errors when e.g. the file using a variable is processed before the file that defines it. Fix by explicitly rooting the sprockets manifest at `application.css`, as suggested here: rails/sprockets#597 (comment)
In sprockets 4.0.0, the `link_directory ../stylesheets .css` directive causes sprockets to process all `.scss` files in an arbitrary order, regardless of any `@import` statements. This leads to undefined variable errors when e.g. the file using a variable is processed before the file that defines it. Fix by explicitly rooting the sprockets manifest at `application.css`, as suggested here: rails/sprockets#597 (comment)
In sprockets 4.0.0, the `link_directory ../stylesheets .css` directive causes sprockets to process all `.scss` files in an arbitrary order, regardless of any `@import` statements. This leads to undefined variable errors when e.g. the file using a variable is processed before the file that defines it. Fix by explicitly rooting the sprockets manifest at `application.css`, as suggested here: rails/sprockets#597 (comment)
So, I don't understand the effects of changing manifest.js the way @zarqman suggests, I don't know if it will cause other problems. I'm reluctant to change I believe Rails 5.2 generates a config/manifest.js that looks like this:
And Rails 6.0 generates a
If Rails is generating a config/manifest.js that doesn't work properly, that is a bug with something. But I'm not sure if the fix is getting Rails to generate a different I think this problem is actually going to trip up a lot of people now that sprockets 4.0.0 final is released. It seems to be doing something... different and backwards incompatible (and perhaps buggy?) than sprockets 3.0, which doesn't seem to be documented... and may not be intended? And may effect anyone who is trying to use a sass variable defined in a file.... elsewhere? in a gem?... and is depending on things to be loaded in the order of sprockets |
Hmm, the example given in https://github.com/rails/sprockets/blob/master/UPGRADING.md for an I wonder if the bug really is that Rails is generating a Def could use some advice from @schneems |
I forgot to link to it previously, but I provided more background on this Rails issue: rails/rails#36204. In short, Adding At worst, if It may be useful for someone to open a new bug/PR on Rails, since Rails 6.0 and Sprockets 4.0 have now both been released. |
My understand of Which, if so, explains why it would break things -- it's trying to take individual partials meant for compilation only in context with other things (like other files that define variables), and trying to compile them individually. It would not explain why it worked with sprockets 3 though. Or why Rails thought this was the proper thing to generate. If it is about top-level targets, it is doing a different thing than require/require_tree are though, since those are about including things into the current 'target'. I am very confused about what's going on though, and need docs and/or explanation from maintainer. |
@jrochkind, yes, my understanding of link, link_directory, and the issue with partials is about the same as yours. I don't specifically recall what changed between Sprockets 3 & 4 (I vaguely remember some kind of conditional somewhere regarding As of version 6, Rails now uses |
Ah, Rails generated an In Rails 6, does it use it with both sprockets 3 and 4 though? Actually I have a Rails 5.2 which does seem to use it once I upgrade to Sprockets 4 -- cause that's what produces the error! So maybe Rails 5.2 with sprockets 4 uses it, but Rails 5.2 with sprockets 3 doesn't. Still very confused. We can work around it in a "cargo cult" way, but I'd like to actually understand what's going on to hopefully contribute a proper fix and document it correctly. |
Thanks @zarqman, that's very helpful. It looks like, based on what @zarqman mentioned, Rails used the setting The solution is to either, as mentioned previously, update |
I have spent some time trying to make sure I understand exactly what's going on and have written it up on my blog.
Feedback from @schneems on any of this would be awesome. |
@jrochkind, I think these two might be what you're looking for:
|
Aha, @schneems pointed out that he already valiantly tried to get Rails to switch this in rails/rails#28430 but it was rejected. So @zarqman, your rails/rails#36204 is actually maybe a dup of that. :( I think they were wrong, and it makes upgrading to sprockets 4 significantly more confusing, and I don't think they considered this than rejecting it. While I think it's not too late, I'm not sure if it will be possible to convince Rails maintainers otherwise. I think this is all ends up very confusing for the user. But will try to at least submit a PR to the Sprockets 4 upgrade guide trying to clear it up -- it takes a lot more words to explain with Rails choice to use |
Setup:
I have three scss files in
app/assets/stylesheets
Expected behavior
I expect that
./bin/rails assets:precompile
compiles the application.scss (just as sprockets 3.x did)Actual behavior
System configuration
Example App
https://github.com/jcoyne/testapp
The text was updated successfully, but these errors were encountered: