Closed umagon closed 3 months ago
I can’t reproduce your issue using the example you provided. Could you record a video instead and show what’s wrong on your side?
sizes
is a very weird attribute and it's quite hard to test it locally because of it interacts with the DPR, especially in the dev tools in Chrome. As far as I can tell, Astro is generating the right code though, so it's really unlikely that there is an Astro issue here.
@Princesseuh Yes it might be my misunderstanding of how sizes works since the output is correct.
@V3RON I have some screenshots
If I use anything above 50px
(or so, I don't know the exact threshold), it jumps to the next size, 200w
.
Closing because this is not an issue with Astro, the markup generated is correct. As I wrote in my previous message, the HTML sizes
attribute is just super confusing to work with because you often can't quite test it correctly by resizing the window / using the dev tools, it's very wonky.
Apologies for the inconvenience, if you run into further issues, don't hesitate asking for help on our Discord: https://astro.build/chat
Astro Info
If this issue only occurs in one browser, which browser is a problem?
Chrome
Describe the Bug
When I use Image component's sizes attribute I get a correct output, but when I check which image gets downloaded I get the wrong one.
I've made an stackblitz demo. In it there is an MyImage component with a sizes attribute that looks like this:
The
sizes
attribute is working weirdly. When I use a device-width of 320px, it should use the180w
version of the image. But a quick inspection of network tab in dev tools shows the200w
version was downloaded.This wrong behavior is so weird I couldn't tell what is actually happening. When I change the first width (
180px
) insizes
andwidths
attributes to20px
, a20px
image (correct) gets downloaded. But when I use anything above50px
, the next image size (200px
) gets downloaded, even if I didn't change the media query at all.What's the expected result?
It should download the correct image taking into account the viewport width.
The output of the example above is:
Maybe this is not an astro bug, but I can't believe nobody has this problem. Maybe I'm not using this component the right way. Would appreciate some help.
Link to Minimal Reproducible Example
https://stackblitz.com/edit/withastro-astro-ebpoea?file=src%2Fcomponents%2FMyImage.astro
Participation