-
Notifications
You must be signed in to change notification settings - Fork 27.8k
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] Images on Safari are getting downloaded multiple times in different sizes #19478
Comments
I've been testing around and I've noticed a couple of things, of course all of this is only happening (in my case) in Safari. first, the behaviour differs from one layout mode to another. for example, setting the layout prop to often this error is showing in the console [Error: ENOENT: no such file or directory, unlink '/Users/elia/Desktop/playground/next-image/.next/cache/images/9G8LlgjhcAHaytCnfziyTyUqLsNnv7Z5zXhyNBUSJGw=/1606475905162.vSeS9FT7kbvQQwhM0jGQCyFkfczi+MxKPZHeoZNnkfQ=.webp'] {
errno: -2,
code: 'ENOENT',
syscall: 'unlink',
path: '/Users/elia/Desktop/playground/next-image/.next/cache/images/9G8LlgjhcAHaytCnfziyTyUqLsNnv7Z5zXhyNBUSJGw=/1606475905162.vSeS9FT7kbvQQwhM0jGQCyFkfczi+MxKPZHeoZNnkfQ=.webp'
} setting the Thank you very much for the time and effort 🙏 |
I am facing similar error messages and in this case no image is shown in the frontend. For me it happens on multiple browsers (Brave on iPadOS and Chrome and Firefox on Windows) and in develop-mode but most of all in a semi-busy production site hosted on Azure.
|
I am seeing this issue as well, also with no image being shown on the frontend as in @ericvrp's case. In my case I am getting a broken image in Safari 14.0.2 on macOS (11.1), as well as Safari on iPadOS, but the image displays in Safari on iOS as well as Firefox (83.0) on macOS.
|
It might be another version (resolution/format) of the image that you are seeing. |
We're also running into this issue with Safari on macos. Requests to the next server when using next/image cause the image resizing process to fail on the first request and so images are not displayed, but subsequent requests seem to succeed. Seen on Safari 13.1.2 on macos 10.13.6 and Safari 14.0.3 on macos 11.2. Next.js 10.0.5 node 10.15.3 |
I am using Next.js 10.0.5 too and all my images that are using next/image are getting downloaded three times in Safari. Any idea how to fix this? |
Currently if you have `sizes` set in `next/image`, the image will likely be downloaded multiple times (usually twice) on Safari (macOS and iOS): the correct size for the viewport, and the original size specified in `src`. Also make sure you have "Ignore Resource Cache" disabled in the Safari Devtools when trying to reproduce:  The root cause is the way Safari handles `<img>`'s attribute updates. Although React updates all the attributes one by one synchronously and programmatically, Safari will still try to fetch the resource immediately and won't wait for other DOM changes to be finished. That means if we set the following 3 attributes in this order: `src`, `srcSet`, `sizes`. Safari will fetch the image when `src` is set. And then once `srcSet` is there it will fetch the resource again based on it. And finally, when `sizes` is updated it might correct the resource URL again. So the fix here is simple: by just reordering those to `sizes`, `srcSet`, `src`, it will only load the image with the correct size only once: <img width="1498" alt="CleanShot 2021-03-09 at 21 05 30@2x" src="https://user-images.githubusercontent.com/3676859/110477852-a27c7700-811e-11eb-88dc-d6e7895f67bd.png"> Fixes #19478.
This issue has been automatically locked due to no recent activity. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you. |
Bug report
Describe the bug
The image component is only requesting the image in the original size on safari for some reason, the requested Url always looks like this
http://localhost:3000/_next/image?url=%2Fitalian-fabric-dark-blue.jpg&w=3840&q=75
.Code:
html output:
and when adding the sizes attributes two images are requested at the same time
http://localhost:3000/_next/image?url=%2Fitalian-fabric-dark-blue.jpg&w=3840&q=75
andhttp://localhost:3000/_next/image?url=%2Fitalian-fabric-dark-blue.jpg&w=640&q=75
code:
output
Our production server is also crashing every time it is visited from a Safari browser (seems to happen more on iOS) and this error is logged
Killed error Command failed with exit code 137.
To Reproduce
here is a minimal codeSandbox.
Expected behaviour
The Image component should load the correct image like in other browsers
System information
Additional context
Add any other context about the problem here.
The text was updated successfully, but these errors were encountered: