inline_svg: 1.5.0 and 1.5.1 can no longer find assets in production

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.


Which version of Rails are you using?

Ruby 2.6.2, Rails 5.2.3

Are you using Webpack at all?

Yes, via webpacker

Are you using Sprockets or Webpacker? Or both?

Both

Are you using your own custom asset_finder?

No

Could you paste your InlineSvg.configure block, if any

Not using one.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 6
  • Comments: 16 (6 by maintainers)

Most upvoted comments

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 InlineSvg::WebpackAssetFinder config, that finder only appears to find files that are precompiled (that is, I run $./bin/webpack before I start my server. If I do that, the finder find’s my files no problem. However, it does not appear to use any assets found via webpack-dev-server or update changes based on if I remove or add files to my images folder.

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.

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.