Problem/Motivation
In getStyledImageSrcset(), createDerivative() is only called when the base JPEG derivative is missing:
if (!file_exists($derivative_uri)) {
$style->createDerivative($uri, $derivative_uri);
}
if (!file_exists($derivative_uri . '.webp')) {
continue;
}
If the JPEG derivative already exists on disk but the .webp file does not — for example because imageapi_optimize_webp was added to the pipeline after derivatives were generated, or because stage_file_proxy fetched the JPEG from a remote environment that hadn't yet produced WebP variants — createDerivative() is never called and the .webp is never produced. That image style variant is silently skipped, leaving the WebP <source> srcset incomplete.
In the worst case, only the smallest size (e.g. 100w) has a pre-existing .webp, causing the browser to always serve that variant regardless of viewport size, resulting in blurry images.
Steps to reproduce
- Have images with pre-existing JPEG derivatives (e.g. via
stage_file_proxyor a previous deployment). - Enable
imageapi_optimize_webpand assign it to the default pipeline. - Visit a page with the responsive image component.
- Inspect the rendered
<picture>markup — the WebP<source>srcset will only contain sizes whose.webpfile already existed on disk.
Proposed resolution
Gate createDerivative() on whether the .webp file exists, not whether the base JPEG exists:
if (!file_exists($derivative_uri . '.webp')) {
$style->createDerivative($uri, $derivative_uri);
}
if (!file_exists($derivative_uri . '.webp')) {
continue;
}
This ensures the imageapi_optimize_webp post-processor always gets a chance to run whenever the .webp is missing, regardless of the state of the base derivative.
Remaining tasks
Review and merge.
User interface changes
None.
API changes
None.
Data model changes
None.
Issue fork pagedesigner_responsive_images-3582456
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #3
elgandoz commented