Serve 2x assets on retina screens via srcset#1058
Closed
PavelMakarchuk wants to merge 1 commit into
Closed
Conversation
OptimisedImage hardcoded dpr = 1, so an image asked to fill a 640px slot was fetched at 640px and then upscaled by the browser to ~1280 physical pixels on every retina/high-DPI display — visibly soft across hero, team photos, blog/research cards, and tracker thumbnails. Switches to a 1x/2x srcset: the browser picks the right asset per device. Low-DPI screens keep using the 1x file (no bandwidth waste), high-DPI screens get the sharper 2x. When the snapped 1x and 2x widths collide (e.g. both round to the same ALLOWED_WIDTHS bucket) we drop the descriptor so the browser doesn't double-fetch the same file. Also factored out the bypass conditions into shouldSkipOptimisation() so the main render branch reads as straight srcset construction. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Author
|
Folding into #1056 per request — both changes affect home page render quality. |
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.
Summary
OptimisedImagehardcodeddpr = 1, so an image asked to fill (say) a 640px slot was fetched at 640px of pixel data and then upscaled by the browser to ~1280 physical pixels on every modern laptop and phone.srcsetso the browser picks the right asset per device. Low-DPI screens keep using the 1x file (no bandwidth waste); high-DPI screens get the sharper 2x.ALLOWED_WIDTHSbucket (e.g.width=1080→ 2x snaps to 1920, butwidth=1200→ 2x also snaps to 1920 → same as 1x at the next-higher bucket in some configurations), thesrcsetdescriptor is dropped to avoid the browser double-fetching identical files./_next/*, dev mode, missing width) intoshouldSkipOptimisation()so the main render branch reads as straightsrcsetconstruction.Affected surfaces
Every consumer of
OptimisedImage— including:Test plan
/uson a retina display and confirm the hero photo and blog preview cards render sharply (compare to before this PR)&w=values at ~2× the rendered widthw=value/_next/*paths still fall through unchanged🤖 Generated with Claude Code