Skip to content

fix(imgproxy,cloudflare): select src the way a generation rule does - #39

Merged
dangreen merged 2 commits into
mainfrom
fix/proxy-src-selection
Sep 3, 2026
Merged

fix(imgproxy,cloudflare): select src the way a generation rule does#39
dangreen merged 2 commits into
mainfrom
fix/proxy-src-selection

Conversation

@dangreen

@dangreen dangreen commented Sep 3, 2026

Copy link
Copy Markdown
Member

What

src, and with it url, was the largest width of the last format of the rule. A build-time generation rule points the default export at the source format instead, falling back to the first format of the list - so the same format field had to be written in opposite orders depending on which tool read it.

Both adapters now make the build-time selection: the variant of the source format, read from the url extension, at the largest width; the first format of the list takes over when the source format is not in it. The source width has no counterpart at runtime, so the largest requested width stands in for it.

source format src before src now
photo.jpg ['jpg', 'webp', 'avif'] avif1200 jpg1200
photo.jpg ['avif', 'webp', 'jpg'] jpg1200 jpg1200
photo.jpg ['webp', 'avif'] avif1200 webp1200
picture.png ['png', 'webp'] webp1200 png1200

Also

toArray is now toUniqArray and deduplicates, which was previously spelled out at every call site as [...new Set(toArray(...))] and for (const width of new Set(widths)).

Notes

Neither package is published yet, so nothing downstream changes.

The documentation for this lives in the website branch - those files are not on main yet.

`src`, and with it `url`, was the largest width of the last format of the
rule, so the format list had to be written in the opposite order to a
build-time rule: the widely supported format first there, last here.

It is now the variant of the source format - read from the url extension -
at the largest width, falling back to the first format of the list when the
source format is not in it. That is the selection a generation rule makes,
minus the source width, which is unknown at runtime.
`toArray` left the deduplication to every call site, which spelled it as
`[...new Set(toArray(...))]` and `for (const width of new Set(widths))`.
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 33744982375

Coverage decreased (-0.05%) to 93.859%

Details

  • Coverage decreased (-0.05%) from the base build.
  • Patch coverage: 15 of 15 lines across 4 files are fully covered (100%).
  • 1 coverage regression across 1 file.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

1 previously-covered line in 1 file lost coverage.

File Lines Losing Coverage Coverage
packages/loader/src/template.ts 1 95.83%

Coverage Stats

Coverage Status
Relevant Lines: 889
Covered Lines: 842
Line Coverage: 94.71%
Relevant Branches: 658
Covered Branches: 610
Branch Coverage: 92.71%
Branches in Coverage %: Yes
Coverage Strength: 79445.87 hits per line

💛 - Coveralls

@dangreen
dangreen merged commit b1dd2a0 into main Sep 3, 2026
7 checks passed
@dangreen
dangreen deleted the fix/proxy-src-selection branch September 3, 2026 10:41
@github-actions github-actions Bot mentioned this pull request Sep 2, 2026
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.

2 participants