Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,14 @@ export const GatsbyImageHydrator: FunctionComponent<GatsbyImageProps> = function
if (hasSSRHtml.complete) {
customOnLoad?.()
storeImageloaded(JSON.stringify(images))
}
hasSSRHtml.addEventListener(`load`, function onLoad() {
hasSSRHtml.removeEventListener(`load`, onLoad)
} else {
hasSSRHtml.addEventListener(`load`, function onLoad() {
hasSSRHtml.removeEventListener(`load`, onLoad)

customOnLoad?.()
storeImageloaded(JSON.stringify(images))
})
customOnLoad?.()
storeImageloaded(JSON.stringify(images))
})
}
return undefined
}

Expand Down Expand Up @@ -157,11 +158,6 @@ export const GatsbyImageHydrator: FunctionComponent<GatsbyImageProps> = function
return
}

// When no ssrHtml is found (develop) we should force render instead of hydrate
if (!hasSSRHtml) {
hydrated.current = true
}

import(`./lazy-hydrate`).then(({ lazyHydrate }) => {
lazyHydrator.current = lazyHydrate(
{
Expand Down
5 changes: 4 additions & 1 deletion packages/gatsby-plugin-image/src/components/lazy-hydrate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ type LazyHydrateProps = Omit<GatsbyImageProps, "as" | "style" | "className"> & {
ref: MutableRefObject<HTMLImageElement | undefined>
}

const IS_DEV = process.env.NODE_ENV === `development`

export function lazyHydrate(
{
image,
Expand Down Expand Up @@ -97,7 +99,8 @@ export function lazyHydrate(
</LayoutWrapper>
)

const doRender = hydrated.current ? render : hydrate
// Force render to mitigate "Expected server HTML to contain a matching" in develop
const doRender = hydrated.current || IS_DEV ? render : hydrate
doRender(component, root.current)
hydrated.current = true

Expand Down