Make sure og source images can be reached on initial deploy

This commit is contained in:
Sam Becker 2024-04-19 11:06:31 -05:00
parent e4d5f75e3c
commit 6906d89523

View File

@ -52,8 +52,14 @@ export default function ImagePhotoGrid({
justifyContent: 'center',
gap,
}}>
{photos.slice(0, count).map(({ id, url }) =>
<div
{photos.slice(0, count).map(async ({ id, url }) => {
const src = getNextImageUrlForRequest(url, nextImageWidth);
// Make sure next/image can be reached from absolute url,
// which may not exist on first pre-render
const doesNextImageExist = await fetch(src)
.then(response => response.ok)
.catch(() => false);
return <div
key={id}
style={{
display: 'flex',
@ -62,8 +68,8 @@ export default function ImagePhotoGrid({
overflow: 'hidden',
}}
>
<img {...{
src: getNextImageUrlForRequest(url, nextImageWidth),
{doesNextImageExist && <img {...{
src,
style: {
width: '100%',
...imagePosition === 'center' && {
@ -71,9 +77,9 @@ export default function ImagePhotoGrid({
},
objectFit: 'cover',
},
}} />
</div>
)}
}} />}
</div>;
})}
</div>
);
}