-
Notifications
You must be signed in to change notification settings - Fork 247
3.4.1: Relative assets urls are converted into absolute ones. Breaking existing code. #486
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
Comments
You can see the breakage in this failing CI https://github.com/AlchemyCMS/alchemy_cms/runs/4300052710?check_suite_focus=true#step:12:127 and what was necessary to fix it https://github.com/AlchemyCMS/alchemy_cms/pull/2218/files as you can also see we have to use a relative url starting from the top most folder (the sprockets lookup path) but it is then turned into an absolute url. Both behaviors seem wrong from what a browser (and a file system) would usually do. Expected behavior:url("img/some.gif") from a file in a folder should return a url url("/assets/components/img/some.gif") and not url("/assets/img/some.gif") while a url("/img/some.gif") should return url("/assets/img/some.gif") |
@jcoyne can you take a look on this one as well please? We should making the absolute path relative to the current asset, and that should fix the issue. |
@rafaelfranca yes, I'll take a look today. |
I see this issue in versions 3.3.0, 3.4.0 and 3.4.1. No problems on 3.2.2. |
@nickcoyne the code from #485 hasn't yet been released, but it is in the main branch. |
ok, thanks @jcoyne, I'll give that a try then. |
This issue still affects us even with the changes in #485. Previously I don't really understand the reasoning behind this change and why these tests are the expected ones: sprockets-rails/test/test_asset_url_processor.rb Lines 52 to 63 in 4e0f168
Is there any way to make sprockets-rails still output the paths as relative like it used to do before v3.3.0? Our asset pipeline relied on sprockets-rails outputting the relative paths and the change in v3.3.0 seems to have made that impossible. |
@valscion This is all driven by the new Rails 7 asset pipeline, which primarily uses sprockets-rails as a post-processor for cssbundling-rails. It was the fix for rails/cssbundling-rails#22 Your knowledge of sprockets-rails and it's traditional uses likely exceeds my own, so your help with this issue would be welcome. It seems that AlchemyCMS may be an outlier in terms of how sprocket-rails is used since you have images in a subdirectory of |
@rafaelfranca I'm way out of my depth here. I've looked but I'm not sure how to go about this. |
Ok well good to know that this is driven by Rails 7 needs 👍. We'll pin our version to 3.2.2 as this backwards-incompatible change was released in v3.3.0 |
As I asked above, can we bump the version to Then we can pin our projects to @rafaelfranca @dhh are you fine with that? |
@tvdeyen We use cssbundling-rails + sprockets-rails on a rails 6.1 app, so that might cause a breaking change for us. It could work if the dependencies didn't exclude rails 6.1. However, I don't think that this breakage was supposed to happen in rails 7. This is a bug that needs to be resolved for all users of this gem. |
@jcoyne could you use proposed 4.0.0.pre in your Rails 6.1 as well? I am not saying that |
@tvdeyen So that everyone better understands the AlchemyCMS use case, are the tinyMCE image assets linked to without the hash digest? It might be that using cssbundling-rails wants all image assets to be digested and your use case is expecting non-digested assets. |
@jcoyne yes, but this is totally unrelated to this issue. The digest gets removed (aka a symlink created) via the But another issue we are seeing is with the fontawesome icon font (and the css bundle they provide). The paths in the stylesheet (you are downloading from their website) are all relative. With |
It does convert them to absolute paths because it is trying to make them into digested assets. I don't think you want these to be digested assets and I don't think we have a way of deciding which assets should be digested and which shouldn't. |
|
@tvdeyen it didn't provide digested urls for every Right now, I don't think (my knowledge is limited), there is a way to keep the functionality you depend on and have the behavior that cssbundling-rails needs without some kind of feature flag. |
Yeah for us, we were relying on The change in And I guess that's what this issue is about — discussing semantics of version numbering. Not about whether there's some sort of a "fix" for how to keep the early behavior. There might also be other gems that have relied, maybe on purpose, maybe by accident, on the old behavior where It's of course up to the maintainers of And yes, the way we use sprockets and sprockets-rails can seem to be quite unorthodox. We know that our way of using sprockets and sprockets-rails can be prone to breakage when a change to the Rails builtin asset pipeline is changed. And that seems to be the case for us here in sprockets-rails gem. For me, I'm a bit sad that we have to pin the gem to v3.2.2 but I also understand that it's a price we must pay for fiddling with the asset pipeline as much as we do. |
Seems like AlchemyCMS also uses the So the way I see it is that v3.3.0 breaks compatibility with the Now that To me, it feels more like a burden for us end users who used |
@valscion @tvdeyen thank you for you feedback on this problem. It's clear that the committers will have to make a decision about how to move forward. Rewinding a released feature is complicated, but we also shouldn't have broken existing apps. One thing I've learned is that sprockets-rails has very little test coverage, especially integration type tests. If someone is able to add those tests, I think this project could be a lot more stable. |
In retrospect, yes, we probably should have bumped the major version. But that's more of a stylistic change. The end result would have been the same: some use patterns would have been incompatible. I don't see the trade off of reverting changes, pushing out a new 3.x release, then doing a separate 4.0 as being worth it at this point, though. We can fix the relative-to-absolute conversion, though. So that the absolute path is translated relative to the path of the asset. @jcoyne, if you want to tackle that, please go ahead, and we can release that in 3.4.x. |
That might work for us, yes. For example, we have the built CSS file living in production in here:
And with .cFMs319K8uCdE_4aIE3wU::before {
content: url(static/icon-sitting-white.72e233bb0680f4a70b717dcea570e673.svg);
} Now this ends up downloading the SVG from here:
With .cFMs319K8uCdE_4aIE3wU::before {
content: url(/static/icon-sitting-white.72e233bb0680f4a70b717dcea570e673.svg);
} So the place it tried to load the SVG from ended up being this one:
...which was happily caught by our CI before it reached production. For us, it would've been OK if the CSS ended up looking like this instead: .cFMs319K8uCdE_4aIE3wU::before {
content: url(/assets/v2/bundle/fi/static/icon-sitting-white.72e233bb0680f4a70b717dcea570e673.svg);
} We've configured our application with: Rails.application.configure do
config.assets.version = 'v2'
config.assets.prefix = File.join('/assets', config.assets.version)
config.assets.digest = true
config.assets.precompile << ['bundle/*']
end and the CSS-file-to-be-precompiled can be found in path
while the SVG file referenced in CSS is in path:
So during precompilation, all the necessary information should be there to go from .cFMs319K8uCdE_4aIE3wU::before {
content: url(static/icon-sitting-white.72e233bb0680f4a70b717dcea570e673.svg);
} to this one: .cFMs319K8uCdE_4aIE3wU::before {
content: url(/assets/v2/bundle/fi/static/icon-sitting-white.72e233bb0680f4a70b717dcea570e673.svg);
} We'd be OK even if the end result would get the digest added to it and become something like this instead: .cFMs319K8uCdE_4aIE3wU::before {
content: url(/assets/v2/bundle/fi/static/icon-sitting-white.72e233bb0680f4a70b717dcea570e673-331b0896fbbe3be736a015ecbb0382c7a837e7aef841467ceb5ab24bb0914d9c.svg);
} |
So, the need for digested asset references in some cases of course existed before. Is it that Rails 7 with css-bundler increases the cases where you want/need this? As I understand it/have experienced it, previously, if you wanted digested assets referenced in a CSS file, you'd have to use something like the sass-rails helper Sprockets on it's own didn't parse The intent of the change seemed to be to make sprockets parse CSS for all I'm not sure there's any way for that to happen backwards compatibly. In the sense that if some people in some cases had non-digested local path references to be in their CSS, which went through sprockets, and they were relying on this... and it's now impossible? I guess it's not possible to meet the desired new use case, by having something in the CSS source indicate that a local digested path should be looked up, instead the need is that all The benefit of releasing a backwards incompat change only in a new version, of course, is that people who have their Gemfiles locked to major version 2 won't get breakages when they update automatically, and people won't have to add the somewhat opaque requirement of locking to |
Could a sprockets configuration option be added, which defaults to old behavior for backwards compat, but allows opt-in to new behavior to parse/transform all relative |
@jrochkind I've opened a draft PR to make this behavior configurable: #489. Can you either provide an example application that reproduces the problem or simply try that PR in your application? The expected behavior would be that when using that branch, your assets work (CSS |
The approach in #489 would work for us and fix the issue with us not being able to upgrade |
@valscion Just want to clarify - were you able to test PR #489 in an application that had previously experienced broken assets when upgrading sprockets-rails? Despite opening that PR, I actually don't work on any applications that were affected by the issue, which is why I was asking above if @jrochkind or someone else could either provide an example application or test the PR in their own private application. I was waiting to take the PR out of the draft state until someone who was affected by this issue could verify the fix. |
Option to turn off rewriting has been shipped in https://github.com/rails/sprockets-rails/releases/tag/v3.4.2. |
In 05dbab2 a breaking change was introduced and released as 3.4.1 as a hotfix for the already breaking 3.4.0
Before sprockets 3.3.0 a url like
url(img/thing.gif)
inside a folder loads the image from the current folder (the folder the file lives in) relatively. This is valid HTML/CSS and every css processor reads this correctly.Now the url is converted into an absolute URL. This breaks a lot of existing frontend code. In a patch level release by the way.
Can we revert this please and release a new version? Then rethink changes made in 3.3.0 and 3.4.0 and release them as a 4.0 instead if a breaking change is intentional/necessary?
The text was updated successfully, but these errors were encountered: