Skip to content

Commit

Permalink
fix(gatsby-plugin-image): Make onLoad callback work on first load (#3…
Browse files Browse the repository at this point in the history
  • Loading branch information
tyhopp committed Aug 12, 2022
1 parent 8bad1a7 commit 3dfc1ec
Showing 1 changed file with 6 additions and 5 deletions.
Expand Up @@ -122,12 +122,13 @@ const GatsbyImageHydrator: FC<GatsbyImageProps> = function GatsbyImageHydrator({
ssrImage.removeAttribute(`data-gatsby-image-ssr`)
}, 0)
} else {
document.addEventListener(`load`, function onLoadListener() {
document.removeEventListener(`load`, onLoadListener)
onStartLoad?.({
wasCached: true,
})

ssrImage.addEventListener(`load`, function onLoadListener() {
ssrImage.removeEventListener(`load`, onLoadListener)

onStartLoad?.({
wasCached: true,
})
onLoad?.({
wasCached: true,
})
Expand Down

0 comments on commit 3dfc1ec

Please sign in to comment.