Repository navigation
fix(upload): use the small format as the 2x candidate in the media library grid - #28007
Conversation
…brary grid The grid always rendered formats.thumbnail, a fixed 245x156 box, so previews were upscaled and blurry on HiDPI screens. Add a srcset with the small format as the 2x candidate. 1x screens keep the thumbnail. Nothing is added when small was not generated or there is no thumbnail.
Adzouz
left a comment
There was a problem hiding this comment.
Hi @santichausis, thanks for the PR 🙏 I tested and it looks good on my side ✅
One nit but it's not part of this PR so I'll approve it
| // Offer the `small` format as the 2x candidate; 1x screens keep the light | ||
| // thumbnail. `small` only exists for images larger than its breakpoint (and | ||
| // when responsive formats are enabled), so it is optional. | ||
| const rawHiDpiURL = formats?.thumbnail?.url |
There was a problem hiding this comment.
Non-blocking, fine as a follow-up: portrait images are still soft on 1x screens. StyledImage uses object-fit: cover, so a ~117px-wide portrait thumbnail is stretched to fill the ~250px card, about 2x upscale even at DPR 1.
Width descriptors would cover that case too, because the browser would pick small whenever the thumbnail is narrower than the card:
srcSet={`${thumbURL} ${formats.thumbnail.width}w, ${smallURL} ${formats.small.width}w`}
sizes="250px"This needs width on the formats (the thumbnail-only type variant doesn't have it) and a sizes value that matches the grid column.
|
This PR has been added to our community triage board as CPR-604. |
AI-generated QA checklistScope / Impact
Manual QA
Edge Cases
Test Setup
Possible QA Automation
Assumptions / Gaps
QA ResolutionAdd |
What does it do?
In the new Media Library grid (
AssetPreviewinAssetsGrid.tsx), the image card now setssrcSetwith thesmallformat as the2xcandidate.srcis unchanged, so 1x screens keep loading the lightthumbnail.srcSetis only added when boththumbnailandsmallexist:smallis only generated when responsive formats are enabled and the original is larger than the breakpoint.thumbnail,srcis already the original, which is larger thansmall.The existing cache-buster is applied to the
smallURL as well, and skipped for signed URLs, same as forsrc.smallis also declared (optional) in the thumbnail-only variant ofFile['formats']so the grid can read it without a cast.Why is it needed?
thumbnailis generated in a fixed245x156box (fit: 'inside'), so a portrait image ends up around 117x156. The card is ~250 CSS px wide, ~500 device px on a HiDPI screen, so the preview is upscaled 3-4x and looks blurry, even thoughsmallalready exists for the same asset.As agreed in the issue, this uses a
srcsetinstead of switching tosmallunconditionally, and leaves the legacy components untouched.How to test it?
small_file; at DPR 1 it loads thethumbnail_file.srcsetis rendered and the card behaves as before.Unit tests added in
AssetsGrid.test.tsx(srcset present, absent withoutsmall, absent withoutthumbnail, cache-buster / signed URL handling).Related issue(s)/PR(s)
Fix #27986
Fixes CPR-604