rsnext/test/integration/image-component
Shu Ding 7dd99faee7
Fix next/image being downloaded multiple times on Safari (#22902)
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:

![CleanShot 2021-03-09 at 21 05 54@2x](https://user-images.githubusercontent.com/3676859/110476820-6399f180-811d-11eb-93ec-5b2482c87884.png)

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.
2021-03-09 19:07:01 +00:00
..
base-path Allow smaller sizes in srcset for image with fill layout and sizes prop (#21670) 2021-02-24 22:57:19 +00:00
basic Fix next/image being downloaded multiple times on Safari (#22902) 2021-03-09 19:07:01 +00:00
custom-resolver Update next/image test (#20986) 2021-01-13 15:05:08 +00:00
default Allow smaller sizes in srcset for image with fill layout and sizes prop (#21670) 2021-02-24 22:57:19 +00:00
typescript Add props objectFit and objectPosition to Image component (#18849) 2020-11-05 19:42:55 +00:00
typescript-style Omit ignored property from <Image/ > to prevent confusion (#18796) 2020-11-04 16:13:07 +00:00