Skip to content
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

Fix typo and add comment to next/image SyntheticEvent #41480

Merged
merged 1 commit into from Oct 17, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 5 additions & 3 deletions packages/next/client/image.tsx
Expand Up @@ -268,11 +268,14 @@ function handleLoading(
setBlurComplete(true)
}
if (onLoadRef?.current) {
// Since we don't have the SyntheticEvent here,
// we must create one with the same shape.
// See https://reactjs.org/docs/events.html
const event = new Event('load')
Object.defineProperty(event, 'target', { writable: false, value: img })
let prevented = false
let stopped = false
const sytheticEvent = {
onLoadRef.current({
...event,
nativeEvent: event,
currentTarget: img,
Expand All @@ -288,8 +291,7 @@ function handleLoading(
stopped = true
event.stopPropagation()
},
}
onLoadRef.current(sytheticEvent)
})
}
if (onLoadingCompleteRef?.current) {
onLoadingCompleteRef.current(img)
Expand Down