Exception thrown by responsive srcset images when the image is not yet in the file system (such as with Stage File Proxy)

Created on 15 November 2016, over 7 years ago
Updated 25 April 2024, 2 months ago

Problem/Motivation

Whenever possible, responsive images should be built with srcset rather than the <picture> tag (more). Also, Stage File Proxy β†’ , S3 File System β†’ , and the Flysystem suite of modules β†’ are common solutions to file storage. Unfortunately, when relying on proxied services for image files that are being rendered through an image style that will output a srcset image tag, an exception is thrown that breaks the entire page.

Steps to reproduce

  1. Install Drupal with the Responsive Images (core) module.
  2. Create a responsive image style that will output a srcset image tag using this technique. The image styles used within the responsive image style should scale only by one dimension.
  3. Create a content type with an image field.
  4. Set that image field's formatter to be a "responsive image" using the style created in Step 2.
  5. Create a piece of content and upload an image that will use that formatter.
  6. Download and enable the Stage File Proxy β†’ contrib module (or any other module that uses a proxied service for storing images) and configure it to point to another origin if a file in the file system does not exist.
  7. Move the image file from Step 5 outside of the current environment's file system, and into the place where the SFP origin points to, in such a way that when using SFP as designed, it would find and download this image file when it realized the current environment's file system didn't yet have it.
  8. Navigate to the node page that should output the image using the responsive image formatter.

Expected result: Upon realizing the file isn't in the current environment's file system, Stage File Proxy should grab it from the origin (assuming it exists there) and should be able to use it when rendering the responsive image.

Actual result: An exception is thrown that breaks the entire page:

LogicException: Could not determine image width for 'public://image-name.jpg' using image style with ID: responsive_image_style. This image style can not be used for a responsive image style mapping using the 'sizes' attribute. in responsive_image_build_source_attributes() (line 391 of core/modules/responsive_image/responsive_image.module).

Notes: This error is not thrown when the responsive image style is configured to output a <picture> element. SFP will work as designed and the page/image will be displayed as expected.

Proposed resolution

Unfortunately, I don't know. Looking for guidance here from those more familiar with this functionality...

I assume that a bug that so heavily relies on a contrib module would normally be that module's problem, but this doesn't quite seem to be the case because the exception never gives SFP a chance to fetch the image. I suppose I could have framed it this way: if the image doesn't exist in the file system, an exception is thrown that breaks the whole page, but I would expect only a broken <img> tag on an otherwise OK page. I didn't because that seems more like a "fix your image" problem than a "developers are going to rely on this to work without issue and it won't" problem.

Remaining tasks

TBD

User interface changes

N/A

API changes

N/A

Data model changes

N/A

πŸ› Bug report
Status

Needs work

Version

11.0 πŸ”₯

Component
Responsive imageΒ  β†’

Last updated 12 days ago

Created by

πŸ‡ΊπŸ‡ΈUnited States guschilds

Live updates comments and jobs are added and updated live.
  • Needs tests

    The change is currently missing an automated test that fails when run with the original code, and succeeds when the bug has been fixed.

Sign in to follow issues

Merge Requests

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.69.0 2024