fix(imgproxy,cloudflare): select src the way a generation rule does - #39
Merged
Conversation
`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))`.
Coverage Report for CI Build 33744982375Coverage decreased (-0.05%) to 93.859%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions1 previously-covered line in 1 file lost coverage.
Coverage Stats
💛 - Coveralls |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
src, and with iturl, 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 sameformatfield 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.
formatsrcbeforesrcnowphoto.jpg['jpg', 'webp', 'avif']avif1200jpg1200photo.jpg['avif', 'webp', 'jpg']jpg1200jpg1200photo.jpg['webp', 'avif']avif1200webp1200picture.png['png', 'webp']webp1200png1200Also
toArrayis nowtoUniqArrayand deduplicates, which was previously spelled out at every call site as[...new Set(toArray(...))]andfor (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
mainyet.