feat: add Picture component for art-directed responsive images - #18
Open
intellix wants to merge 1 commit into
Open
feat: add Picture component for art-directed responsive images#18intellix wants to merge 1 commit into
intellix wants to merge 1 commit into
Conversation
Adds a `Picture` component that renders a native `<picture>` element with art-directed `<source media>` children. The browser downloads only the source whose media query matches, so serving different desktop/mobile banner images no longer double-fetches under loading="eager"/fetchpriority="high" (a common LCP regression when hiding a second <Image> with CSS). - Reuses the existing Image component as the fallback <img> and the getSrcSet/getSizes helpers for per-source responsive srcsets. - Per-source width/height/aspectRatio overrides (fall back to Picture-level). - Global useImageProvider config (resolutions, imageTransformer$) applies with no extra wiring. Image's public API is unchanged. - Adds the first component spec (picture.spec.tsx, 5 tests via createDOM) and wires the qwik-image test target to run vitest directly (the @nrwl/vite:test executor is incompatible with the pinned vitest 0.30/vite 4.3). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
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
Issue: #17
Adds a
Picturecomponent for art-directed responsive images — serving different image files per viewport (e.g. a full-width desktop banner and a smaller mobile banner) via a native<picture>element.Why
A common pattern for different mobile/desktop banners is two
<Image>tags toggled with CSS (hidden md:block). Butloading="eager"andfetchpriority="high"are honored by the browser even fordisplay:noneelements, so both images get fetched on the critical path — an LCP regression Lighthouse flags.<picture>with<source media>fixes this at the platform level: the browser evaluates the media queries and downloads only the matching source.loading/fetchpriorityon the fallback<img>apply to whichever source is selected, so exactly one request is made and correctly prioritized.How
Imagecomponent as the required fallback<img>child, and the existinggetSrcSet/getSizeshelpers for each source's responsivesrcset.width/height/aspectRatiooverrides (fall back toPicture-level values) for tuning each source's generatedsrcset.resolutions/imageTransformer$come from the existingImageContext, so the globaluseImageProviderconfig applies with no extra wiring.Image's public API and behavior are unchanged —Pictureis a new, additive export.Tests
Adds
picture.spec.tsx— 5 tests via@builder.io/qwik/testing'screateDOM— covering: fallback-only render, one<source>per entry with correctmedia/type,loading/fetchpriorityon the<img>(verified as the last child), each source'ssrcflowing throughimageTransformer$, and per-sourcewidthoverride affecting that source'ssrcset.🤖 Generated with Claude Code