Skip to content

fix: Convert og-image format if needed - #459

Open
soniaklimas wants to merge 1 commit into
developfrom
MS-968-convert-og-image-format-if-needed
Open

fix: Convert og-image format if needed#459
soniaklimas wants to merge 1 commit into
developfrom
MS-968-convert-og-image-format-if-needed

Conversation

@soniaklimas

Copy link
Copy Markdown
Contributor

I want to merge this change because it converts opengraph-image format if needed.

Pull Request Checklist

  • Test the changes locally to ensure they work as expected.
  • Document the testing process and results in the pull request description. (Screen recording, screenshot etc)
  • Include new tests for any new functionality or significant changes.
  • Ensure that tests cover edge cases and potential failure points.
  • Document the impact of the changes on the system, including potential risks and benefits.
  • Provide a rollback plan in case the changes introduce critical issues.
  • Update documentation to reflect any changes in functionality.

@vercel

vercel Bot commented Sep 10, 2025

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
nimara-ecommerce Ready Ready Preview Comment Sep 15, 2025 5:06pm
2 Skipped Deployments
Project Deployment Preview Comments Updated (UTC)
nimara-docs Skipped Skipped Sep 15, 2025 5:06pm
nimara-ecommerce-stripe Skipped Skipped Sep 15, 2025 5:06pm

@GrzegorzDerdak
GrzegorzDerdak force-pushed the MS-968-convert-og-image-format-if-needed branch from 582ed64 to 785d3ea Compare September 15, 2025 17:01
@vercel
vercel Bot temporarily deployed to Preview – nimara-ecommerce-stripe September 15, 2025 17:01 Inactive
@vercel
vercel Bot temporarily deployed to Preview – nimara-docs September 15, 2025 17:01 Inactive
Base automatically changed from develop to staging September 16, 2025 06:14
@GrzegorzDerdak
GrzegorzDerdak changed the base branch from staging to develop September 17, 2025 09:28
@prelint

prelint Bot commented May 26, 2026

Copy link
Copy Markdown

Decision review: OG image format conversion for collection pages

Product decisions in this change

  1. Collection thumbnails are always converted to a standard format before being used in social sharing images. Previously, the raw source URL was used directly, which could fail silently if the source image was in a format the OG renderer cannot process.

  2. Collections without thumbnails now show the fallback branded image inside the full collection template (including any text overlays, collection name, etc.) rather than as a standalone full-bleed image. This is a side effect of unifying the two previously separate code paths into one.

  3. OG image quality for collections with thumbnails is fixed at 75. Where previously the source image was used at its native quality, social sharing images now always use a specific quality level.


Assessment

1. Format conversion for OG images

Agree. The OG image renderer cannot process certain modern image formats (WebP, AVIF) that CDNs increasingly serve by default. Without this, social shares for collections using those formats would silently break or show blank images. Routing through the Next.js image optimizer before compositing is the correct solution.

Option What it gives users What it costs Effort to change later
Current approach (route through optimizer) Social images always render, regardless of source format Creates a runtime dependency on the image optimizer being reachable at compose time Low — URL construction is localized
Raw source URL (previous behavior) One fewer network hop during rendering Silent failures for WebP/AVIF source images Low
Detect format and conditionally convert Converts only when needed More complex logic, format detection is fragile Medium

2. Fallback template behavior change for collections without thumbnails

Disagree with the current approach — this is likely an unintentional regression. Previously, a collection with no thumbnail got a clean, intentional branded image as its social share. Now it gets the collection template with the generic brand image dropped into the thumbnail position. Depending on what the collection template looks like, this could mean the fallback social image shows a collection name or description on top of the brand image — which may read as confusing or unfinished to someone encountering it on social media. The two code paths were separate for a reason: the fallback was a deliberate design choice, not just a missing image. Collapsing them erases that distinction.

Option What it gives users What it costs Effort to change later
Current approach (unified template, fallback as thumbnail src) Consistent code path Fallback social image may show collection text on top of brand image — unintended appearance Low
Restore separate early return for no-thumbnail case Fallback social image remains a clean branded image, as designed Slightly more code Low

3. Fixed quality at 75 for collection OG images

Broadly correct. OG images are served to social platform crawlers at fixed dimensions and are not user-adjustable; 75 is a reasonable tradeoff between file size and visual fidelity for that use case. The only scenario where this becomes a product concern is if the source thumbnails are heavily compressed to begin with and a double-compression at 75 introduces visible artifacts — but that is a quality-of-content concern, not a structural product decision.


Open questions

  • Was the change in fallback behavior (decision 2) intentional? Does the full collection template produce a sensible-looking OG image when the thumbnail is the generic brand image?
  • Are there other OG image routes in this codebase (product pages, category pages) that have the same format compatibility problem and were not updated?
  • Does the Next.js image optimizer allow the Saleor CDN domain in its allowed sources? If not, collections with thumbnails would silently fall back to a broken image rather than the fallback brand image.

Recommendation

Ship with changes

The core format conversion fix is correct and solves a real rendering problem. However, the unification of the fallback code path appears to be an unintentional side effect that changes the social sharing appearance for collections without thumbnails. Restore the early return for the no-thumbnail case to preserve the original fallback behavior, while keeping the optimizer routing for the thumbnail case.

@prelint prelint Bot left a comment

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.

apps/storefront/src/app/[locale]/(main)/collections/[slug]/opengraph-image/route.tsx:59

1 finding(s) posted as inline comments.

Comment on lines 47 to +59

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

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.

@lukas-szewczyk

Copy link
Copy Markdown
Member

Nimara migrated to trunk-based development in #718, with main as the only long-lived branch. Please confirm here by 2026-07-30 whether this work is still active. For confirmed work, rebase the branch onto current main, resolve any drift, and retarget the PR to main. After the seven-day window, unconfirmed PRs will be closed with migration instructions. Please do not add new work to develop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants