Skip to content

Fix 404s for AVIF sources when storePicturesInWEBP is enabled#264

Open
LorenzoGalassi wants to merge 1 commit into
Niels-IO:masterfrom
LorenzoGalassi:fix/263-avif-webp-srcset
Open

Fix 404s for AVIF sources when storePicturesInWEBP is enabled#264
LorenzoGalassi wants to merge 1 commit into
Niels-IO:masterfrom
LorenzoGalassi:fix/263-avif-webp-srcset

Conversation

@LorenzoGalassi

Copy link
Copy Markdown

Fixes #263

Problem

When the source image is .avif and nextImageExportOptimizer_storePicturesInWEBP is enabled (the default), the optimizer and the component disagree about the output extension:

  • optimizeImages.ts rewrites the extension to WEBP for every supported input when storePicturesInWEBP is set — including AVIF — so only photo-opt-<width>.WEBP files are written to disk.
  • ExportedImage (and the legacy variant) excludes AVIF from its extension-substitution list, so the generated srcset keeps .AVIF paths.

Result: every optimized variant of an AVIF source 404s in production.

Fix

Add "AVIF" to the substitution list in example/src/ExportedImage.tsx and example/src/legacy/ExportedImage.tsx, matching what the optimizer writes. Behavior with storePicturesInWEBP=false is unchanged (extension stays AVIF, which matches the .AVIF files the optimizer writes in that mode).

Verification

Rendered ExportedImage with src="/images/photo.avif" and storePicturesInWEBP=true via react-dom/server against the built package:

Before:

srcset: /images/nextImageExportOptimizer/photo-opt-1200.AVIF 1x, /images/nextImageExportOptimizer/photo-opt-3840.AVIF 2x

After:

srcset: /images/nextImageExportOptimizer/photo-opt-1200.WEBP 1x, /images/nextImageExportOptimizer/photo-opt-3840.WEBP 2x
  • npm run build passes
  • npm test passes (5 tests, 42 snapshots)

The optimizer rewrites the output extension to WEBP for every supported
input format when storePicturesInWEBP is set, including AVIF. But the
extension substitution in ExportedImage (and its legacy variant) skipped
AVIF, so the generated srcset kept .AVIF paths pointing at files that
were never written, causing 404s for every optimized variant in
production.

Add AVIF to the substitution list so the generated URLs match the files
the optimizer writes to disk.

Fixes Niels-IO#263
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

AVIF source images generate .AVIF srcset paths but optimizer writes .WEBP files (404 in production)

1 participant