Commit graph

10 commits

Author SHA1 Message Date
Steven
fd0d0f5a87
Exclude srcset from svg image (#44308)
The default behavior for svg is `dangerouslyAllowSVG: false` which means we won't try to optimize the image because its vector (see #34431 for more).

However, svg was incorrectly getting the `srcset` attribute assigned which would contain duplicate information like:

```
/test.svg 1x, /test.svg 2x
```

So this PR makes sure we treat svg the same as `unoptimized: true`, meaning there is no `srcset` generated. Note that this PR won't change the behavior if `loader` is defined or if `dangerouslyAllowSVG: true`.
2022-12-23 16:57:16 +00:00
l1qu1d
723311bde9
Revert "Remove useState from next/image (#43587)" (#44094)
# Reverts vercel/next.js#43587

PR #43587 breaks the `placeholder="blur"` property on the `<Image />`
component by keeping the `blurStyles`, e.g. the blurred image, after the
image is loaded.

**This regression does _not_ introduce any breaking changes or bugs.**

---

The reason for the original PR was:
> This PR remove `React.useState()` from the `next/image` component. It
was only used in the `onError` case and it was causing Safari to become
very slow when there were many images on the same page. We were seeing
1s delay blocking the main thread when there were about 350 images on
the same page. Chrome and Firefox were not slow.

The original PR is a performance improvement for Safari on a corner
case.

Additionally, when tackling this performance improvement again, the
`blurStyle` needs to know when the the image is done loading so it can
get rid of the blur. The state is updated in `handeLoading()` and isn't
just used `onError`.

## Fixes issues

- Fixes #43829
- Fixes #43689

## To reproduce

For reference this when #43587 was pulled into Next.js
[v13.0.6-canary.3](https://github.com/vercel/next.js/blob/v13.0.6-canary.3/packages/next/client/image.tsx)

- Regress the `image.tsx` to
[v13.0.6-canary.2](https://github.com/vercel/next.js/blob/v13.0.6-canary.2/packages/next/client/image.tsx)
- Do a local build with the regressed `image.tsx` on (current canary
build)
[v13.0.8-canary.0](https://github.com/vercel/next.js/releases/tag/v13.0.8-canary.0)
- Example code, (import any image you like) make sure to use
`placeholder="blur"`
```typescript
import Image from 'next/image'
import CatImage from '../public/cat.png'

<Image
    src={CatImage}
    width={500}
    height={500}
    alt="Cat"
    priority
    placeholder="blur"
/>
```
- Image will still have the blur after the image is loaded
- Before and after screenshot


![before](https://user-images.githubusercontent.com/1037693/208206084-bd6fa143-ca19-4fda-9f4e-8fcec9836848.png)


![after](https://user-images.githubusercontent.com/229881/208470446-3a00eac6-f82e-4017-bd9f-7c6145456959.png)

Co-authored-by: Steven <steven@ceriously.com>
2022-12-19 12:10:23 -05:00
Steven
7a7e7d4f93
Remove useState from next/image (#43587)
This PR remove `React.useState()` from the `next/image` component. It
was only used in the `onError` case and it was causing Safari to become
very slow when there were many images on the same page. We were seeing
1s delay blocking the main thread when there were about 350 images on
the same page. Chrome and Firefox were not slow.
2022-11-30 18:30:02 -08:00
Laityned
369d6b76c4
Imageloader: collect images serverside to include images from staticp… (#41554)
In #41548, I show that I would like to provide an object with images in
getStaticProps. The StaticImageData is parsed correctly and provided as
a prop to the page. Nonetheless, the image is not available in the
static directory. Therefore the image is not shown. This is also
addressed in issue #29571. The underlying cause is that the import of
the image is removed from the client bundle and only present in the
server bundle.

Evaluating the next-image-loader shows that the file is only placed in
the static directory if emitted from the client bundle by firing
this.emitFile. By changing this to only emitting the file from the
serverside bundle in the webpackloader, static images loaded in the
getStaticProps are made available properly as well as images directly
used in componts (so present in server and client bundle).

This would PR would prevent the circumventing solution which enforces
that the StaticImageData should be present in the client side bundle
while it will also be present in the staticprops.

<!--
Thanks for opening a PR! Your contribution is much appreciated.
To make sure your PR is handled as smoothly as possible we request that
you follow the checklist sections below.
Choose the right checklist for the change that you're making:
-->

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added
- [ ] Errors have a helpful link attached, see `contributing.md`


Closes #42783, Fixes #42443

Co-authored-by: Diederik <diederik@digitalpatrol.nl>
2022-11-23 09:28:53 -05:00
Steven
676be08d32
Warn when legacy prop detected on next/image (#42102)
Instead of hard error, we can try to convert legacy props to the new
props and print a warning.

We still recommend upgrading by running one (or both) codemods because
the new component no longer has a wrapping `<span>`.

<img width="616" alt="image"
src="https://user-images.githubusercontent.com/229881/198756393-7d981686-f4db-485b-9f5f-1ff614d35959.png">

Read more: https://nextjs.org/docs/messages/next-image-upgrade-to-13
2022-10-29 22:22:08 -07:00
teobler
e2e1048b71
fix: Data URL images with 'fill' are always triggering 'missing sizes' warning (#42030)
fixes https://github.com/vercel/next.js/issues/42006

this issue occurred because images with `data url` src start with `blob`
and `data` will be mark as `unoptimized`, then its `sizes` will be
assigned with `undefined`.

I just skip the check for `data url` images, if there is any better
solution, we can have a discuss here.

## Bug

- [x] Related issues linked using `fixes #number`
- [x] Integration tests added

- [x] Make sure the linting passes by running `pnpm build && pnpm lint`
- [x] The "examples guidelines" are followed from [our contributing
doc](https://github.com/vercel/next.js/blob/canary/contributing/examples/adding-examples.md)

Co-authored-by: Steven <steven@ceriously.com>
2022-10-28 18:08:04 -04:00
Steven
191710ddfe
Show error message when using legacy props on new next/image (#41930)
This PR shows a better error message when using legacy props on new
`next/image` (introduced in Next.js 13) and makes the codemod more
discoverable.
2022-10-27 12:17:28 -04:00
Steven
d260ad2adf
Change data-nimg attribute on next/image (#41612)
For `next/legacy/image`, the `data-nimg` has the `layout` prop value. 

Since `next/image` doesn't have a `layout` prop, we can use `fill` when
the fill prop is used or fallback to `1`.
2022-10-22 11:58:08 -07:00
Steven
fe762d329f
Fix next/image svg blur placeholder with fill (#41573)
This PR fixes two bugs:

- Fixes #40419 
- Fixes #41393 

The first is when the aspect ratio of the `width` and `height` does not
match the aspect ratio of the `blurDataURL` provided. This can result in
artifacts around the edges. The solution is to add
`preserveAspectRatio="none"`.

The second is when there is no `width` or `height` provided (which is
normal when using `fill`) so the viewBox was undefined. This can also
cause artifacts around the edges. The solution is to change the blur
technique from gaussian to css filter, similar to `next/legacy/image`.

Note: css blur might be [slower in
firefox](https://bugzilla.mozilla.org/show_bug.cgi?id=925025) which is
why we'll only use it for this corner case.
2022-10-19 13:21:41 -07:00
Steven
241195ddd6
BREAKING CHANGE: Rename next/image to next/legacy/image & rename next/future/image to next/image (#41399)
This PR introduces breaking changes by renaming components.

- Rename `next/image` to `next/legacy/image`
- Rename `next/future/image` to `next/image`

The diff is very confusing because both components are very similar so git got confused.
2022-10-14 01:59:22 +00:00