rsnext/packages/next/client
Alex Castle a0d44ca311
Allow smaller sizes in srcset for image with fill layout and sizes prop (#21670)
Currently, the image component doesn't handle use of the `sizes` property with `layout="fill"` and `layout="responsive"` very well for small viewports. It will never include sizes smaller than the smallest viewport (640px) in the srcset, so even if you specify `sizes="30vw"` in your image, you have to download the full-viewport-width image on small devices. 

This PR adds logic such that if you use `layout="fill"` and include a `sizes` property, the image component will include the full range of image sizes in the `srcset`.

It also includes an optimization where it finds the smallest `vw` value in the sizes value and combines that with the smallest viewport width, and uses that as the floor of the srcset. It does this so it doesn't unnecessarily increase transfer size by including ALL sizes. This is still a conservative optimization--for 95% of cases, taking the _largest_ `vw` size would work, but I don't see a way to do that without breaking a few corner cases.

The case of a sizes prop with `px` values is fixed but not optimized--though generally that case is less of a good fit for the fill or responsive layout anyway.
2021-02-24 22:57:19 +00:00
..
dev Remove unnecessary unfetch polyfill for dev (#20589) 2020-12-29 21:01:42 +00:00
experimental-script.tsx fix(link): cancel idle callback on unmount (#22072) 2021-02-11 13:51:41 -05:00
head-manager.ts refactor(client): add return types (#20728) 2021-01-05 15:11:37 +00:00
image.tsx Allow smaller sizes in srcset for image with fill layout and sizes prop (#21670) 2021-02-24 22:57:19 +00:00
index.tsx Add isPreview field to router (#21638) 2021-02-18 18:34:33 +00:00
link.tsx Only create locale domain links if on locale domain (#22032) 2021-02-11 10:18:24 +00:00
next-dev.js Remove the static optimization indicator (#18629) 2020-11-02 09:27:36 +01:00
next.js Shave a few bytes off the bootstrap code (#14457) 2020-06-22 17:50:17 +00:00
normalize-trailing-slash.ts fix basepath trailing slash (#15200) 2020-07-15 23:53:31 +00:00
page-loader.ts refactor(client): add return types (#20728) 2021-01-05 15:11:37 +00:00
performance-relayer.ts refactor(client): add return types (#20728) 2021-01-05 15:11:37 +00:00
polyfills.js polyfills 2020-03-30 16:26:25 -04:00
request-idle-callback.ts fix(link): cancel idle callback on unmount (#22072) 2021-02-11 13:51:41 -05:00
route-loader.ts fix(link): cancel idle callback on unmount (#22072) 2021-02-11 13:51:41 -05:00
router.ts Add isPreview field to router (#21638) 2021-02-18 18:34:33 +00:00
use-intersection.tsx fix(link): cancel idle callback on unmount (#22072) 2021-02-11 13:51:41 -05:00
with-router.tsx refactor(client): add return types (#20728) 2021-01-05 15:11:37 +00:00