-
Notifications
You must be signed in to change notification settings - Fork 72
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
1.5.0 and 1.5.1 can no longer find assets in production #98
Comments
Strangely, explicitly forcing the old asset finder seems to work (we are double checking): Rails.application.config.after_initialize do |app|
InlineSvg.configure do |config|
config.asset_finder = app.instance_variable_get(:@assets)
end
end |
@shepmaster thanks for opening this issue and sorry about the problems you're having with 1.5x.
This is very strange because the Railtie should automatically configure that for you during App initialization. inline_svg/lib/inline_svg/railtie.rb Lines 17 to 20 in e32d1f6
I guess this must also mean that your app's assets are not being precompiled by Heroku on deployment, which is the default behavior. If your assets were being precompiled then there would be no Sprockets |
Hi @jamesmartin, I had the same problem when I went from We use Sprockets and Webpacker. But it is still Sprockets that manages the compilation of SVG. Of course we precompile our assets in production. I'm trying to investigate. I'll come back to you if I have any further information. |
+1 for this issue. maybe because of this line: v1.5.0...v1.5.1#diff-f77654af79391ea695bddcf725119364R21 if you have webpacker it will use it for asset finder |
Exactly why I think it's so very strange!
We certainly intend for the assets to be precompiled. The Heroku log states:
Wouldn't it fallback to the inline_svg/lib/inline_svg/railtie.rb Lines 17 to 28 in e32d1f6
Said another way, why wouldn't |
Using this initializer also appears to work: Rails.application.config.after_initialize do |app|
InlineSvg.configure do |config|
config.asset_finder = InlineSvg::StaticAssetFinder
end
end |
And forcing the loader to be
|
Ideal is to have both finders work together. Of course check if webpack if available, if not only static finder works |
I think that may be a key problem for our case. Our app uses both the asset pipeline and Webpack (via Webpacker) as we slowly migrate from the former to the latter. The two tools process completely independent sets of assets for us. As I understand the problem, Prior to 1.5, the fallback would have gone to the static asset finder, which would find the precompiled assets . |
@shepmaster thanks for clarifying that you're using both Sprockets and Webpacker while you transition. I added a note to the readme when I released 1.5.0 that was intended to help with any confusion, but it was not clear enough:
I'm going to add a note about using the In your case I think it's sufficient to just configure the InlineSvg.configure do |config|
config.asset_finder = InlineSvg::StaticAssetFinder
end Given this is a breaking change, I probably should have bumped the major version to 2.0. Apologies again for the disruption. 🤔
That's kind of a complicated problem because Webpacker doesn't expose any reliable method to ask, "is Webpacker bundling images". We could check the Webpacker manifest file and start greping for paths that appear to be images, but that's probably not very reliable. |
I think I'm going to remove the auto-selection of Webpacker and make it "opt-in" for now. This is going to break too many Heroku Apps and it's not reasonable to make everybody do manual configuration to get back existing functionality. |
I've released v1.5.2, which completely reverts the automatic Webpacker detection and makes Webpack "opt-in" by default, meaning that if you're using Sprockets to serve assets (either dynamically, or precompiled), there should be no additional configuration required. Please update to this version and let me know if you have any problems. Sorry for all the trouble these last couple of releases have caused. |
Sorry, I thought I communicated that in the initial comment.
Yep, but it wasn't part of the release notes or changelog that Dependabot provided for our upgrade.
And in our case, webpack is bundling some images, just not those that we are using inline_svg for. In webpack land, we are using
Not at all! Thank you for your time and maintenance of a useful library! |
@shepmaster I'm going to close this out now. Thanks again for taking the time to open up an issue and describe the problems you faced. |
Thought I would chime in and see if a bit of extra info could help. I am using Rails 6.0rc1 - Ruby 2.5.3 and inline_svg v1.5.2 and I am only using webpacker (no sprockets). When I use the This is the finder that I was using before (1.3) the 1.5.2 update: class WebpackerAssetFinder
class FoundAsset
require 'open-uri'
attr_reader :path
def initialize(path)
@path = path
end
def pathname
if Webpacker.dev_server.running?
begin
asset = open(webpacker_dev_server_url)
tempfile = Tempfile.new(path)
tempfile.binmode
tempfile.write(asset.read)
tempfile.rewind
tempfile
rescue StandardError => e
Rails.logger.error "Error creating tempfile: #{e}"
raise
end
else
Rails.application.root.join("public", path.gsub(/\A\//, ""))
end
end
private
def webpacker_dev_server_url
"#{Webpacker.dev_server.protocol}://#{Webpacker.dev_server.host_with_port}#{path}"
end
end
def find_asset(filename)
if webpack_asset_path = Webpacker.manifest.lookup(filename)
FoundAsset.new(webpack_asset_path)
end
end
end
# Override the Sprockets asset finder. This is my old homebrew method.
InlineSvg.configure do |config|
config.asset_finder = WebpackerAssetFinder.new
end and it still works fine with the 1.5.2 version plugin. |
@richjdsmith thanks for the information. As this seems to be a problem with the interaction between inline_svg and the Webpacker dev server would you mind opening a separate issue for this? Also, if you're motivated to help work on merging your working asset finder with the current version, that would be much appreciated. Thanks 🙏 |
I am still debugging this, but I figured I'd open an issue earlier in case other people have the same problem.
We were previously using 1.4.0 with seemingly no issues, but on upgrading to 1.5.0 (or 1.5.1) we now get:
<!-- SVG file not found: 'logo-black.svg' -->
The corresponding view is pretty basic:
= inline_svg "logo-black.svg", class: "welcome-logo"
What's extra strange is that this only appears when we've deployed to Heroku, not in local development.
Ruby 2.6.2, Rails 5.2.3
Yes, via webpacker
Both
No
Not using one.
The text was updated successfully, but these errors were encountered: