-
Notifications
You must be signed in to change notification settings - Fork 27k
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
next/image not properly sizing images #44244
Comments
Nice catch and detailed reporting. 🙏 |
I am facing the same issue. Are there any updates ? |
Are you considering the pixel density of your device? In your screenshot the srcset contains If you use a |
Same problem, with page router as well as app router (13.3.1). |
Facing the same problem:
Source image is 200x200 pixels but generated |
@romainbriand +1 |
Currently having the same problem, source image is 720px in width, but rendered size is 750px in width -- messing with aspect ratio thus displaying rather blurry image. |
Facing the same problem. I'm getting lower score in PageSpeed Insights for the mobile version due to "Properly size images" opportunity. |
I currently have the same problem, too |
I'm still having this issue on 13.5.1.
Here's a permalink with the issue: https://651f9af212fba00008bba0ed--extraordinary-cucurucho-baaf57.netlify.app/ |
@Pedromigacz You're using
next/image will fetch a 3840px image because that's the next image breakpoint. See https://nextjs.org/docs/app/api-reference/components/image#devicesizes to custom define it in also, nit: As to why it's timing out, that sounds like some other issue... (sorry to spam everyone on this thread) |
This comment has been minimized.
This comment has been minimized.
What actually happens when I pass a 100vw prop to sizes? |
@pjaws , I have same issue, do you have any updates? |
This comment has been minimized.
This comment has been minimized.
setting
|
This comment has been minimized.
This comment has been minimized.
Same issue still present in 14.2.4 e.g. an Image component with the following: seems to correctly construct srcset when inspecting (albeit pointlessley up to the max breakpoint of 3840), but always loads the 1200 breakpoint version even on mobile. |
I had the same issue and after two days of pulling my hair out, I concluded that this is a feature and not a bug… (Although I’m not sure all reported issues here are due to the same cause...) As someone above already mentioned: You can easily test this in the dev tools when enabling the DPR dropdown and switching between 1/2/3 DPR settings.
If you enable an emulated device in the browser, it will use the appropriate DPR for that device. --> I haven’t found a way to avoid this behavior besides just using a regular ol’ img-tag with x descriptors. Another (overcomplicated) way might be to use the new-ish getImageProps() to create an image-set and tell it to use the same image size for all resolutions – but that's just an outlandish theory I haven't tested (yet). Also: unless you set/override them manually in the .config, Next uses default deviceSizes and imageSizes to generate the srcSet which are: -> which might explain why @romainbriand is getting 48x48 and 96x96 instead of 40/80 if sizes prop is set
hope it helps :) |
I noticed next/image's size is set differently depending on where you host your Next.js project. I uploaded a 1 page Next.js project displaying an image on Netlify and Vercel. On Vercel, the image's intrinsic size is 1920x1674 - https://newapp-eight-tawny.vercel.app/ These values can be seen in the bottom right corner of each image below.
Here is the code for both pages
|
I'm having issues getting Next to actually return the resized image(s) from the API. TL;DR— using Also relates to: |
Verify canary release
Provide environment information
Which area(s) of Next.js are affected? (leave empty if unsure)
Image optimization (next/image, next/legacy/image)
Link to the code that reproduces this issue
https://github.com/pjaws/next-image-example
To Reproduce
With
fill
propdiv
with desired aspect ratio padding, i.e.padding-top: calc(2/3 * 100%);
next/image
as child of that divsizes
attribute with desired breakpoints/widthssrcset
is always the same regardless of what's insizes
Without
fill
prop, external imagenext/image
with remote image,width
andheight
props specifiedWithout
fill
prop, local imagenext/image
with local image, nowidth
orheight
specifiedDescribe the Bug
In almost every case, the image requested by
next/image
is larger than expected, resulting in unnecessarily large file sizes.For images with the
fill
prop, thesizes
attribute doesn't seem to actually do anything. In the screenshot below, images that should be around 396px are loading at 640px (1200px screen, 33vw image).For images without
fill
, instead of generating smaller files for smaller devices, the requested image is usually much larger than the specified width and height. In the screenshot below, an image that should be a maximum of 800x533px is being loaded at a width of 1920px on a screen 375px wide.This can also be seen on your own example page where the local Vercel image is set to 1000x1000px, but actually loads the full-size 1600px image at a device width of 375px.
Expected Behavior
"Always serve correctly sized image for each device"
I'm not expecting magic, but currently
next/image
is doing the opposite of what I want/expect. It would be nice to have some way to load smaller images at smaller screen sizes.Which browser are you using? (if relevant)
Chrome 108.0.5359.124
How are you deploying your application? (if relevant)
No response
The text was updated successfully, but these errors were encountered: