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

  1. Have images with pre-existing JPEG derivatives (e.g. via stage_file_proxy or a previous deployment).
  2. Enable imageapi_optimize_webp and assign it to the default pipeline.
  3. Visit a page with the responsive image component.
  4. Inspect the rendered <picture> markup — the WebP <source> srcset will only contain sizes whose .webp file 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.

Command icon 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

elgandoz created an issue. See original summary.

elgandoz’s picture

Status: Needs review » Closed (outdated)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.