Skip to content
Open
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 @@ -45,33 +45,22 @@ export async function GET(
return new Response("Not found", { status: 404 });
}

if (!collection?.thumbnail?.url) {
return new ImageResponse(
(
<div
style={{
display: "flex",
width: "100%",
height: "100%",
}}
>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={new URL(
"og-hp.png",
clientEnvs.NEXT_PUBLIC_STOREFRONT_URL,
).toString()}
alt={t("common.logo")}
style={{
maxWidth: "100%",
maxHeight: "100%",
objectFit: "contain",
}}
/>
</div>
),
{ ...size },
);
let finalImageUrl;

if (collection?.thumbnail?.url) {
// Construct the Vercel-optimized URL
const optimizedUrl = new URL("/_next/image", new URL(request.url).origin);

optimizedUrl.searchParams.set("url", collection.thumbnail.url);
optimizedUrl.searchParams.set("w", String(size.width));
optimizedUrl.searchParams.set("q", "75");
finalImageUrl = optimizedUrl.toString();
} else {
// Fallback if no thumbnail is available
Comment on lines 47 to +59

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Warning

The no-thumbnail fallback path previously returned early with a dedicated simple layout rendering og-hp.png using objectFit: contain. It now falls through to the full collection template where the same og-hp.png is rendered with objectFit: cover, cropping and distorting an image not designed for that context. Social platforms will silently receive a visually broken OG image for any collection without a thumbnail instead of the intended brand fallback.

finalImageUrl = new URL(
"og-hp.png",
clientEnvs.NEXT_PUBLIC_STOREFRONT_URL,
).toString();
}

return new ImageResponse(
Expand Down Expand Up @@ -109,8 +98,10 @@ export async function GET(
>
{/* eslint-disable-next-line @next/next/no-img-element */}
<img
src={collection.thumbnail.url}
alt={collection.thumbnail.alt || t("collections.collection-image")}
src={finalImageUrl}
alt={
collection?.thumbnail?.alt || t("collections.collection-image")
}
style={{ width: "100%", height: "100%", objectFit: "cover" }}
/>
</div>
Expand Down