next.js
208c4f44 - fix(image): findClosestQuality returns 0 for low quality values (#89621)

Commit
30 days ago
fix(image): findClosestQuality returns 0 for low quality values (#89621) Fixes #89620 Fix `findClosestQuality` returning `0` when the `quality` prop on `<Image>` is set to a low value (e.g. `quality={1}`), which causes the image optimization server to reject the request with a 400 error. ### Cause The `reduce` call in `findClosestQuality` used `0` as its initial accumulator. Since `0` is not a valid quality value (must be 1-100), it would win the "closest" comparison for any `quality <= 37` with the default `qualities: [75]` config. This produced `q=0` in the image URL, which the server rejects. ### Fix Description Changed the `reduce` initializer from `0` to `config.qualities[0]`. This is safe because the early return above already handles the empty array case, so `config.qualities[0]` is always defined when reached. Added a unit test for `quality=1` with `qualities=[75]` to verify it returns `75` instead of `0`. --------- Co-authored-by: Steven <steven@ceriously.com>
Parents
Loading