Skip to content

Assets helpers raises an exception about missing assets in production. #2524

@inkstak

Description

@inkstak

After upgrading ViewComponent to version 4.x, the helpers image_tag and image_path doesn't work in production anymore without helpers.

Steps to reproduce

# my_component.erb.html

<picture>
  <source srcset="<%= image_path("logos-darkmode.svg") %>" media="(prefers-color-scheme: dark)">
  <%= image_tag("logos.svg") %>
</picture>

Expected behavior

Both helpers worked in VC 3.23.2
Those helpers should work after upgrading to VC 4.x

Actual behavior

After upgrading to VC 4.1.1, both helpers work fine in development & test environnements.
The component generates the expected HTML :

<picture>
  <source srcset="/assets/logos-darkmode-99c6f31b19c24a73b9b60cfe89a0070cc5ec2776e4171b370921ca74a85eda43.svg" media="(prefers-color-scheme: dark)">
  <img src="/assets/logos-24f7064723c71fbca50589433206b28b204a74d20f01ab25e178071c017ed608.svg">
</picture>

In production, it raises an exception about missing assets:

ActionView::Template::Error (The asset "logos-darkmode.svg" is not present in the asset pipeline.)
Caused by: Sprockets::Rails::Helper::AssetNotFound (The asset "logos-darkmode.svg" is not present in the asset pipeline.)

I checked the logs and the assets folder : they are not missing.

Using the helpers proxy fixed the issue :

# my_component.erb.html

<picture>
  <source srcset="<%= helpers.image_path("logos-darkmode.svg") %>" media="(prefers-color-scheme: dark)">
  <%= helpers.image_tag("logos.svg") %>
</picture>

System configuration

Rails version: 8.0.4

Ruby version: 3.4.4

Gem version: 4.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions