Unverified Commit e61820e0 authored by Steven's avatar Steven Committed by GitHub

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

- Fix typo 
- Add comment
- Link back to react docs
- Remove unnecessary variable
parent a75b3238
...@@ -268,11 +268,14 @@ function handleLoading( ...@@ -268,11 +268,14 @@ function handleLoading(
setBlurComplete(true) setBlurComplete(true)
} }
if (onLoadRef?.current) { 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') const event = new Event('load')
Object.defineProperty(event, 'target', { writable: false, value: img }) Object.defineProperty(event, 'target', { writable: false, value: img })
let prevented = false let prevented = false
let stopped = false let stopped = false
const sytheticEvent = { onLoadRef.current({
...event, ...event,
nativeEvent: event, nativeEvent: event,
currentTarget: img, currentTarget: img,
...@@ -288,8 +291,7 @@ function handleLoading( ...@@ -288,8 +291,7 @@ function handleLoading(
stopped = true stopped = true
event.stopPropagation() event.stopPropagation()
}, },
} })
onLoadRef.current(sytheticEvent)
} }
if (onLoadingCompleteRef?.current) { if (onLoadingCompleteRef?.current) {
onLoadingCompleteRef.current(img) onLoadingCompleteRef.current(img)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment