feat(assets): Add support for srcset and a Picture component#8620
feat(assets): Add support for srcset and a Picture component#8620Princesseuh merged 18 commits intomainfrom
srcset and a Picture component#8620Conversation
🦋 Changeset detectedLatest commit: 41f5fc6 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
!preview picture |
|
63e341e to
7398d63
Compare
|
!preview picture |
|
|
!preview picture |
|
!preview picture |
1 similar comment
|
!preview picture |
|
!preview picture |
sarah11918
left a comment
There was a problem hiding this comment.
Looking great @Princesseuh ! I made some small suggestions here, and I think a tiny bit more hand-holding description could make sense in one or two places, so see what you think!
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
sarah11918
left a comment
There was a problem hiding this comment.
I love where the changset landed! I just saw one tiny missing "the" somewhere, but good to go!
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
jasikpark
left a comment
There was a problem hiding this comment.
looks great! thanks so much for championing this!
| <picture> | ||
| <source srcset="..." type="image/avif" /> | ||
| <source srcset="..." type="image/webp" /> | ||
| <img src="..." alt="My super image in multiple formats!" /> |
There was a problem hiding this comment.
will the img here be equivalent to the above image + densities example? a la "show the original file in the root image source?
|
|
||
| const image = await getImage(props); | ||
|
|
||
| const additionalAttributes: Record<string, any> = {}; |
There was a problem hiding this comment.
Mostly so we don't have to check the attributes before using them, since it doesn't really matter (it's classic Astro serializing, so it supports everything)
|
|
||
| const fallbackImage = await getImage({ | ||
| ...props, | ||
| format: fallbackFormat, |
There was a problem hiding this comment.
ah, so the answer is yes!
| densities: props.densities, | ||
| }); | ||
|
|
||
| const additionalAttributes: Record<string, any> = {}; |
There was a problem hiding this comment.
| const additionalAttributes: Record<string, any> = {}; | |
| const additionalAttributes: Record<string, unknown> = {}; |
perhaps?
| } | ||
| } | ||
|
|
||
| // TypeScript doesn't know this, but because of previous hooks we always know that targetWidth and targetHeight are defined |
There was a problem hiding this comment.
why not have multiple return points, so typescript does know they're defined?
There was a problem hiding this comment.
Yeah, we could probably accept type params on image services, and have like a prop for validated props and stuff.
|
Thanks for your work! I was looking forward to it. I'll go and use it instead of my own little script, as soon as I get to it. |
Changes
This implements the following RFC: withastro/roadmap#715. Please refer to it for more details on how the feature work.
Testing
Added tests
Docs
withastro/docs#4866