-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(assets): Add support for srcset
and a Picture component
#8620
Conversation
🦋 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This PR is blocked because it contains a minor
changeset. A reviewer will merge this at the next release if approved.
!preview picture |
|
63e341e
to
7398d63
Compare
!preview picture |
|
!preview picture |
!preview picture |
1 similar comment
!preview picture |
!preview picture |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I love where the changset landed! I just saw one tiny missing "the" somewhere, but good to go!
Co-authored-by: Sarah Rainsberger <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will the img
here be equivalent to the above image + densities example? a la "show the original file in the root image source?
@@ -23,6 +23,12 @@ if (typeof props.height === 'string') { | |||
} | |||
|
|||
const image = await getImage(props); | |||
|
|||
const additionalAttributes: Record<string, any> = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not unknown
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah, so the answer is yes!
densities: props.densities, | ||
}); | ||
|
||
const additionalAttributes: Record<string, any> = {}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why not have multiple return points, so typescript does know they're defined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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