Use image renditions for the editor's thumbnails - #242
Merged
Merged
Conversation
The media library grid, the media picker, the article list and the featured-image preview all drew their thumbnails from the original file. The library is mostly camera originals, so a page of the media grid downloaded dozens of multi-megabyte photos to draw 150px squares. The API now sends resized renditions with every library image and featured image. These thumbnails pass them to the browser as a srcset, with `sizes` matching each layout. Images inserted into article bodies are untouched: their URL is saved into the content, and that must stay the original. The featured-image preview keeps its renditions alongside the URL they belong to, because the URL can also be typed or pasted, and a stale set must never be shown against a different image. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019EcFyy8aqNnUd75CDPY6Bx
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.
Why
The editor still draws every thumbnail from the original file. The library is mostly camera originals (often 5–80 MB), so the media grid downloads dozens of full-size photos to draw ~150px squares. The article list does the same for its 48px thumbnails. The API already sends resized renditions with these images (#239, #241), so the editor just needs to use them.
Change
lib/imageVariants.ts: anImageVarianttype andsrcSetFor(). It returnsundefinedwhen there are no renditions, so the attribute is omitted, never empty.srcSet+sizeson:photo_urlis saved, as before.srcstays the original everywhere, so images the backfill hasn't reached look exactly as they do now.trixImageHtml). Their URL is saved into the content and must stay the original. Readers get the renditions throughcontent_image_variants(Return renditions for the images inside an article body #240).Verified
vitest: 23/23, including new tests forsrcSetFor(including the empty and missing cases) and a picker test checking a tile keeps the original assrcand gets the renditions assrcset.npm run build(tsc -b+ vite) passes.eslintreports no new issues; the oneexhaustive-depswarning ineditArticleView.tsxis already onmain.🤖 Generated with Claude Code
https://claude.ai/code/session_019EcFyy8aqNnUd75CDPY6Bx