Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## History In PR #35889, `onError` prop was added explicitly on the `Image` component, but it was ommitted from the `ImageElement` component. In result, the callback didn't work at all. ## Now This PR deletes the `onError` prop from explicitly defined props. Explicitly adding `onError` on the `const imgElementArgs` is considered, but deleting the defined prop from `Image` is more reasonable because the prop isn't used in `Image` component. ## Bug - [x] Related issues linked using `fixes #number` - [ ] Integration tests added - [ ] Errors have helpful link attached, see `contributing.md` Co-authored-by: Steven <229881+styfle@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
66 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
test/integration/image-component/default/pages/on-error.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { useState } from 'react' | ||
import Image from 'next/image' | ||
|
||
const Page = () => { | ||
return ( | ||
<div> | ||
<h1>Test onError</h1> | ||
<p> | ||
If error occured while loading image, native onError should be called. | ||
</p> | ||
<ImageWithMessage id="1" src="/test.png" layout="fill" /> | ||
|
||
<ImageWithMessage id="2" src="/nonexistent-img.png" layout="fill" /> | ||
<div id="footer" /> | ||
</div> | ||
) | ||
} | ||
|
||
function ImageWithMessage({ id, ...props }) { | ||
const [msg, setMsg] = useState('no error occured') | ||
const style = | ||
props.layout === 'fill' | ||
? { position: 'relative', width: '64px', height: '64px' } | ||
: {} | ||
|
||
return ( | ||
<> | ||
<div className="wrap" style={style}> | ||
<Image | ||
id={`img${id}`} | ||
onError={(e) => { | ||
const msg = `error occured while loading ${e.target.id}` | ||
setMsg(msg) | ||
}} | ||
{...props} | ||
/> | ||
</div> | ||
<p id={`msg${id}`}>{msg}</p> | ||
<hr /> | ||
</> | ||
) | ||
} | ||
|
||
export default Page |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters