Skip to content

EC-1209 - Fix og_image variant crash when product has no images - #26

Open
lee-farrell-lu wants to merge 2 commits into
spree:mainfrom
lee-farrell-lu:EC-1209-fix-og-image-variant-store-social-image
Open

lee-farrell-lu wants to merge 2 commits into
spree:mainfrom
lee-farrell-lu:EC-1209-fix-og-image-variant-store-social-image

Conversation

@lee-farrell-lu

@lee-farrell-lu lee-farrell-lu commented Jun 9, 2026

Copy link
Copy Markdown

When a product has no images, page_image falls back to current_store.social_image. Unlike Spree::Asset attachments, social_image has no named variants registered, causing Rails to raise 'Cannot find variant :og_image for Spree::Store#social_image'.

Only use variant: :og_image when the image is a product asset, not when it falls back to the store's social_image.

From our Sentry logging:

Error: [Sentry] - ActionView::Template::Error: Cannot find variant :og_image for Spree::Store#social_image (ActionView::Template::Error)

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced Open Graph image meta tag logic to render more accurately and prevent incorrect image display when sharing content socially.

When a product has no images, page_image falls back to
current_store.social_image. Unlike Spree::Asset attachments,
social_image has no named variants registered, causing Rails to raise
'Cannot find variant :og_image for Spree::Store#social_image'.

Only use variant: :og_image when the image is a product asset,
not when it falls back to the store's social_image.
@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@damianlegawiec, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 19 minutes and 13 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c65b1e29-f028-4ac1-a3fd-9496ad675670

📥 Commits

Reviewing files that changed from the base of the PR and between 7c41c03 and 8b84d53.

📒 Files selected for processing (1)
  • storefront/app/views/themes/default/spree/shared/_meta_tags.html.erb

Walkthrough

The OG image meta tag rendering logic in the meta tags template is refined with a narrowed condition that prevents rendering when the page_image is a Spree::Store instance, even if @product is present.

Changes

OG Image Meta Tag Condition

Layer / File(s) Summary
OG image rendering condition
storefront/app/views/themes/default/spree/shared/_meta_tags.html.erb
The conditional guarding OG image rendering now checks both that @product is present and that page_image is not a Spree::Store, refining the previous @product-only condition.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~5 minutes

Poem

A little condition refined with care,
No Store images floating in the air! 🐰
One line adjusted, the meta tags gleam,
OG images now exactly as they scheme.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing a crash when the og_image variant is called on a product with no images.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
storefront/app/views/themes/default/spree/shared/_meta_tags.html.erb (1)

25-29: 💤 Low value

LGTM!

The condition correctly prevents the crash by excluding Spree::Store records from using the :og_image variant. When page_image falls back to current_store.social_image (which lacks the :og_image variant registration), the explicit dimensions are used instead.

The logic flow is sound:

  • Product pages with product images → use :og_image variant
  • Product pages without images (store fallback) → use explicit dimensions
  • Non-product pages → use explicit dimensions

One optional improvement would be adding an inline comment explaining why the Store exclusion exists:

  <%# Product assets have :og_image variant; store social_image does not %>
  <% if `@product` && !page_image.record.is_a?(Spree::Store) %>

This would help future maintainers understand the variant availability constraint, but it's not critical given the PR description documents the issue well.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@storefront/app/views/themes/default/spree/shared/_meta_tags.html.erb` around
lines 25 - 29, Add a short inline comment above the conditional that checks
`@product` and page_image.record.is_a?(Spree::Store) to explain why Spree::Store
is excluded (product assets register the :og_image variant but the store's
social_image does not), so future maintainers understand why the code uses the
:og_image variant for product images and explicit width/height for
store/non-product images; reference the conditional and the spree_image_url
calls that use variant: :og_image vs width/height to locate where to place the
comment.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@storefront/app/views/themes/default/spree/shared/_meta_tags.html.erb`:
- Around line 25-29: Add a short inline comment above the conditional that
checks `@product` and page_image.record.is_a?(Spree::Store) to explain why
Spree::Store is excluded (product assets register the :og_image variant but the
store's social_image does not), so future maintainers understand why the code
uses the :og_image variant for product images and explicit width/height for
store/non-product images; reference the conditional and the spree_image_url
calls that use variant: :og_image vs width/height to locate where to place the
comment.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b2dce52d-e963-4a58-b482-0b8fd1c83089

📥 Commits

Reviewing files that changed from the base of the PR and between dcc7530 and 7c41c03.

📒 Files selected for processing (1)
  • storefront/app/views/themes/default/spree/shared/_meta_tags.html.erb

Comment thread storefront/app/views/themes/default/spree/shared/_meta_tags.html.erb Outdated
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